/*Z dane NMEA zpravy vypreparuje potrebne informace*/
/*Autor: Zbynek*/
#include "GPS_dekoduj.h"
#include <string.h>
NMEA_GPRMC GPRMC_informace;

/************************************************************************
* Funkce: dekoduj_zpravu_GPS
* Ucel:  Z RX0_buffer vytahne informace o soucasne poloze, je tam ulozena cela veta RMC
* Vstup: Zadny
* Vystup:  Zadny                                                                      
************************************************************************/
void dekoduj_zpravu_GPS (uint8_t* NMEA_retezec, uint8_t NMEA_delka)
{

        uint8_t i = 0, j = 0, k = 0, l = 0, m = 0;
        uint8_t pocet_carek = 0;
        uint8_t po_tecce = 0;
        for ( i = 0; i < NMEA_delka; i++)
        {
                if (pocet_carek == 1)
                {
                        
                        if(NMEA_retezec[i] == '.')
                                po_tecce = 1;
                        if (po_tecce == 0)
                        {
                                if (j == 2 || j == 5)
                                {
                                        GPRMC_informace.UTC_time[j] = ':';
                                        j++;
                                }
                                GPRMC_informace.UTC_time[j] = NMEA_retezec[i];
                                j++;
                        }
                }
                else if (pocet_carek == 2)
                {
                        GPRMC_informace.Status_GPS[0] = NMEA_retezec[i-1];
                }
                else if (pocet_carek == 3 || pocet_carek == 4)
                {
                        GPRMC_informace.Latitude[k] = NMEA_retezec[i];
                        k++;
                }
                else if (pocet_carek == 5 || pocet_carek == 6)
                {
                        GPRMC_informace.Longitude[l] = NMEA_retezec[i];
                        l++;
                }               
                else if (pocet_carek == 9)
                {
                        if (m == 2 || m == 5)
                        {
                                GPRMC_informace.Datum[m] = '.';
                                m++;
                        }
                        GPRMC_informace.Datum[m] = NMEA_retezec[i];
                        m++;
                }
                if (NMEA_retezec[i] == ',')
                {
                        pocet_carek++;
                }
                if (pocet_carek >9)
                {
                        GPRMC_informace.UTC_time[j] = 0;
                        GPRMC_informace.Latitude[k-1] = 0;
                        GPRMC_informace.Longitude[l-1] = 0;
                        GPRMC_informace.Datum[m-1] = 0;
                        GPRMC_informace.Status_GPS[1] = 0;
                        i = 0, j = 0, k = 0, l = 0, m = 0;
                        po_tecce = 0;
                        break;  // nema vyznam dal zapisovat, potrebne je ulozeno.
                }
        }
}