Добавлены файлы времени

This commit is contained in:
Степанов Станислав 2025-03-26 16:14:04 +03:00
parent 83a147ee62
commit 63e2f271b5
2 changed files with 111 additions and 0 deletions

33
Inc/Nmea0183Parser_Time.h Normal file
View File

@ -0,0 +1,33 @@
//
// Created by villuton on 24.03.25.
//
#ifndef WEACTARTRY_NMEA0183PARSER_TIME_H
#define WEACTARTRY_NMEA0183PARSER_TIME_H
#include <stdint-gcc.h>
#include "stdbool.h"
typedef struct {
uint8_t hour;
uint8_t minute;
uint8_t second;
uint16_t millisecond;
} tNmeaUtc;
typedef struct {
uint8_t day;
uint8_t month;
uint8_t year;
} tNmeaDate;
typedef struct {
tNmeaUtc utc;
tNmeaDate date;
} tNmeaTime;
bool Nmea0183ParseUtc(char *utcString, char const *utcStringEnd, tNmeaUtc *utc);
bool Nmea0183ParseDate(char *utcString, char const *utcStringEnd, tNmeaDate *date);
#endif //WEACTARTRY_NMEA0183PARSER_TIME_H

78
Src/Nmea0183Parser_Time.c Normal file
View File

@ -0,0 +1,78 @@
//
// 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;
}