s = serialport("COM4", 115200);

%

gotGGA = false;
while (~gotGGA)
    gpsLine = readline(s);
    if (contains(gpsLine, "GGA") )
        gotGGA = true;
    end
end
gpsLine

%

ggaFields = split(gpsLine, ',')
latString = ggaFields(3)
decPtIndex = strfind(latString, ".")
latMin = str2double(extractAfter(latString, decPtIndex-3))
latDeg = str2double(extractBefore(latString, decPtIndex-2))
latDD = latDeg + latMin / 60.0
if(ggaFields(4) == "S")
    latDD = -1.0 * latDD;
end

lonString = ggaFields(5)
decPtIndex = strfind(lonString, ".")
lonMin = str2double(extractAfter(lonString, decPtIndex-3))
lonDeg = str2double(extractBefore(lonString, decPtIndex-2))
lonDD = lonDeg + lonMin / 60.0
if(ggaFields(6) == "W")
    lonDD = -1.0 * lonDD;
end

timeStamp = datetime(ggaFields(2), 'InputFormat', 'HHmmss.SS')
