/* Private */
TM_GPS_Result_t TM_GPS_INT_Do(TM_GPS_t* GPS_Data, char c) {
	if (TM_GPS_INT_FlagsOk(GPS_Data)) {
		TM_GPS_INT_ClearFlags(GPS_Data);				/* Data were valid before, new data are coming, not new anymore */
		GPS_Data->Status = TM_GPS_Result_OldData;		/* Data were "new" on last call, now are only "Old data", no NEW data */
	}
	if (c == '$') {										/* Start of string detected */
		TM_GPS_Star = 0;								/* Star detection reset */
		TM_GPS_CRC = 0;									/* Reset CRC */
		GPS_Term_Number = 0;							/* First term in new statement */
		GPS_Term_Pos = 0;								/* At position 0 of a first term */
		GPS_Term[GPS_Term_Pos++] = c;					/* Add character to first term */
	} else if (c == ',') {
		TM_GPS_INT_Add2CRC(c);							/* Add to parity */
		GPS_Term[GPS_Term_Pos++] = 0;					/* End of term */
		TM_GPS_INT_CheckEmpty(GPS_Data);				/* Check if term is empty */
		TM_GPS_INT_CheckTerm(GPS_Data);					/* Check term */
		GPS_Term_Number++;								/* Increase term number */
		GPS_Term_Pos = 0;								/* At position 0 of a first term */
	} else if (c == '\n') {
		GPS_Term_Number = 0;							/* Reset term number */
#ifndef GPS_DISABLE_GPGSV
		/* Check for GPGSV statement */
		if (TM_GPS_Statement == GPS_GPGSV && GPGSV_StatementsCount == GPSGV_StatementNumber) {
			TM_GPS_INT_SetFlag(GPS_FLAG_SATSDESC);		/* Set flag */
		}
#endif
	} else if (c == '\r') {
		GPS_Term[GPS_Term_Pos++] = 0;					/* End of character string */
		TM_GPS_CRC_Received = TM_GPS_INT_Hex2Dec(GPS_Term[0]) * 16 + TM_GPS_INT_Hex2Dec(GPS_Term[1]);	/* Between * and \r are 2 characters of Checksum */
		if (TM_GPS_CRC_Received != TM_GPS_CRC) {		/* CRC is not OK, data failed somewhere */			
			TM_GPS_INT_ClearFlags(GPS_Data);			/* Clear all flags */
		}
		GPS_Term_Number = 0;							/* Reset term number */
	} else if (c == '*') {
		TM_GPS_Star = 1;								/* Star detected */
		GPS_Term[GPS_Term_Pos++] = 0;					/* Add 0 at the end */
		TM_GPS_INT_CheckEmpty(GPS_Data);				/* Check empty */
		TM_GPS_INT_CheckTerm(GPS_Data);					/* Check term */		
		GPS_Term_Number++;								/* Increase term number */
		GPS_Term_Pos = 0;								/* At position 0 of a first term */
	} else {
		/* Other characters detected */
		if (!TM_GPS_Star) {								/* If star is not detected yet */
			TM_GPS_INT_Add2CRC(c);						/* Add to parity */
		}
		GPS_Term[GPS_Term_Pos++] = c;					/* Add to term */
	}
	return TM_GPS_INT_Return(GPS_Data);					/* Return current GPS status */
}
TM_GPS_Result_t TM_GPS_INT_Return(TM_GPS_t* GPS_Data) {
	uint8_t i;
	if (TM_GPS_INT_FlagsOk(GPS_Data)) {
		TM_GPS_FirstTime = 0;							/* Clear first time */
		
		/* Set data */
#ifndef GPS_DISABLE_GPGGA
		GPS_Data->Latitude = TM_GPS_INT_Data.Latitude;
		GPS_Data->Longitude = TM_GPS_INT_Data.Longitude;
		GPS_Data->Satellites = TM_GPS_INT_Data.Satellites;
		GPS_Data->Fix = TM_GPS_INT_Data.Fix;
		GPS_Data->Altitude = TM_GPS_INT_Data.Altitude;
		GPS_Data->Time = TM_GPS_INT_Data.Time;
#endif
#ifndef GPS_DISABLE_GPRMC
		GPS_Data->Speed = TM_GPS_INT_Data.Speed;
		GPS_Data->Date = TM_GPS_INT_Data.Date;
		GPS_Data->Validity = TM_GPS_INT_Data.Validity;
		GPS_Data->Direction = TM_GPS_INT_Data.Direction;
#endif
#ifndef GPS_DISABLE_GPGSA
		GPS_Data->HDOP = TM_GPS_INT_Data.HDOP;
		GPS_Data->VDOP = TM_GPS_INT_Data.VDOP;
		GPS_Data->PDOP = TM_GPS_INT_Data.PDOP;
		GPS_Data->FixMode = TM_GPS_INT_Data.FixMode;
		for (i = 0; i < 12; i++) {
			GPS_Data->SatelliteIDs[i] = TM_GPS_INT_Data.SatelliteIDs[i];
		}
#endif
#ifndef GPS_DISABLE_GPGSV
		GPS_Data->SatellitesInView = TM_GPS_INT_Data.SatellitesInView;
		for (i = 0; i < GPS_MAX_SATS_IN_VIEW; i++) {
			GPS_Data->SatDesc[i] = TM_GPS_INT_Data.SatDesc[i];
		}
#endif
		TM_GPS_INT_ReturnWithStatus(GPS_Data, TM_GPS_Result_NewData);	/* Return new data */
	}
	
	if (TM_GPS_FirstTime) {
		TM_GPS_INT_ReturnWithStatus(GPS_Data, TM_GPS_Result_FirstDataWaiting);	/* We are first time */
	}
	TM_GPS_INT_ReturnWithStatus(GPS_Data, TM_GPS_Result_OldData);	/* Return old data */
}
Exemplo n.º 3
0
/* Private */
extern TM_GPS_Result_t TM_GPS_INT_Do(TM_GPS_Data_t* GPS_Data, char c) {
	if (TM_GPS_INT_FlagsOk()) {
		/* Data were valid before, new data are coming, not new anymore */
		TM_GPS_INT_ClearFlags();
		/* Data were "new" on last call, now are only "Old data", no NEW data */
		GPS_Data->Status = TM_GPS_Result_OldData;
	}
	if (c == '$') {		
		/* Star detection reset */
		TM_GPS_Star = 0;
		/* Reset CRC */
		TM_GPS_CRC = 0;
		/* First term in new statement */
		TM_GPS_Term_Number = 0;
		/* At position 0 of a first term */
		TM_GPS_Term_Pos = 0;
		/* Add character to first term */
		TM_GPS_Term[TM_GPS_Term_Pos++] = c;
	} else if (c == ',') {
		/* Add to parity */
		TM_GPS_INT_Add2CRC(c);
		/* Add 0 at the end */
		TM_GPS_Term[TM_GPS_Term_Pos++] = 0;
		
		/* Check term */
		TM_GPS_INT_CheckTerm(GPS_Data);
		
		/* Increase term number */
		TM_GPS_Term_Number++;
		/* At position 0 of a first term */
		TM_GPS_Term_Pos = 0;
	} else if (c == '\n') {
	
	} else if (c == '\r') {
		TM_GPS_Term[TM_GPS_Term_Pos++] = 0;
		
		/* Between * and \r are 2 characters of Checksum */
		TM_GPS_CRC_Received = TM_GPS_INT_Hex2Dec(TM_GPS_Term[0]) * 16 + TM_GPS_INT_Hex2Dec(TM_GPS_Term[1]);
		
		if (TM_GPS_CRC_Received != TM_GPS_CRC) {
			/* CRC is not OK, data failed somewhere */
			/* Clear all flags */
			TM_GPS_INT_ClearFlags();
		}
	} else if (c == '*') {
		/* Star detected */
		TM_GPS_Star = 1;
		/* Add 0 at the end */
		TM_GPS_Term[TM_GPS_Term_Pos++] = 0;
		
		/* Check term */
		TM_GPS_INT_CheckTerm(GPS_Data);
		
		/* Increase term number */
		TM_GPS_Term_Number++;
		/* At position 0 of a first term */
		TM_GPS_Term_Pos = 0;
	} else {
		/* Other characters detected */
		
		/* If star is not detected yet */
		if (!TM_GPS_Star) {
			/* Add to parity */
			TM_GPS_INT_Add2CRC(c);
		}
		
		/* Add to term */
		TM_GPS_Term[TM_GPS_Term_Pos++] = c;
	}
	return TM_GPS_INT_Return(GPS_Data);
}