78 lines
2.4 KiB
C
78 lines
2.4 KiB
C
//
|
|
// Created by villuton on 24.03.25.
|
|
//
|
|
#include "Nmea0183Parser_Time.h"
|
|
#include "Nmea0183Parser_Private.h"
|
|
|
|
|
|
#define NMEA_HourStrLen (2)
|
|
#define NMEA_MinuteStrLen (2)
|
|
#define NMEA_SecondStrLen (2)
|
|
|
|
#define NMEA_HourStrOffset (0)
|
|
#define NMEA_MinuteStrOffset (NMEA_HourStrOffset + NMEA_HourStrLen)
|
|
#define NMEA_SecondStrOffset (NMEA_MinuteStrOffset + NMEA_MinuteStrLen)
|
|
#define NMEA_UTC_PointStrOffset (1)
|
|
#define NMEA_DecimalSecondStrOffset (NMEA_SecondStrOffset + NMEA_SecondStrLen + NMEA_UTC_PointStrOffset)
|
|
|
|
#define NMEA_UTC_PointPosition (6)
|
|
|
|
/**
|
|
* \brief Functions of a low level for analysis of
|
|
* packages of NMEA stream.
|
|
* UTC utc parsing.
|
|
* @param utcString
|
|
* @param utcStringEnd
|
|
* @param utc
|
|
* @return
|
|
*/
|
|
bool Nmea0183ParseUtc(char *utcString, char const *utcStringEnd, tNmeaUtc *utc) {
|
|
|
|
uint32_t len = utcStringEnd - utcString;
|
|
if(len < 6){
|
|
return false;
|
|
}
|
|
|
|
utc->hour = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_HourStrOffset, NMEA_HourStrLen);
|
|
utc->minute = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_MinuteStrOffset, NMEA_MinuteStrLen);
|
|
utc->second = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_SecondStrOffset, NMEA_SecondStrLen);
|
|
|
|
if (utcString[NMEA_UTC_PointPosition] == '.') {
|
|
uint8_t decimalPortionLen = len - NMEA_HourStrLen + NMEA_MinuteStrLen + NMEA_SecondStrLen + NMEA_UTC_PointStrOffset;
|
|
utc->millisecond = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_DecimalSecondStrOffset, decimalPortionLen);
|
|
utc->millisecond *= 1000 / (10 * decimalPortionLen);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
#define NMEA_DayOffset (0)
|
|
#define NMEA_DayLen (2)
|
|
#define NMEA_MonthOffset (NMEA_DayOffset + NMEA_DayLen)
|
|
#define NMEA_MonthLen (2)
|
|
#define NMEA_YearOffset (NMEA_MonthOffset + NMEA_MonthLen)
|
|
#define NMEA_YearLen (2)
|
|
/**
|
|
* \brief Functions of a low level for analysis of
|
|
* packages of NMEA stream.
|
|
* Date parsing.
|
|
* @param utcString
|
|
* @param utcStringEnd
|
|
* @param date
|
|
* @return
|
|
*/
|
|
bool Nmea0183ParseDate(char *utcString, char const *utcStringEnd, tNmeaDate *date) {
|
|
|
|
uint32_t len = utcStringEnd - utcString;
|
|
|
|
if (len != 6) {
|
|
return false;
|
|
}
|
|
|
|
date->day = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_DayOffset, NMEA_DayLen);
|
|
date->month = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_MonthOffset, NMEA_MonthLen);
|
|
date->year = Nmea0183ParseShortCharsDecimalNumber(utcString + NMEA_YearOffset, NMEA_YearLen);
|
|
|
|
return true;
|
|
} |