/*
 * gps.h
 *
 *  Created on: Nov 15, 2019
 *      Author: Bulanov Konstantin
 */
#ifndef GPS_H_
#define GPS_H_

#include "string.h"
#include "stdio.h"
#include "stdbool.h"
#include "stm32f1xx_hal.h"

#define GPS_DEBUG	0
#define GPSBUFSIZE  128       // GPS buffer size

typedef struct{

    // calculated values
    float dec_longitude;
    float dec_latitude;
    float altitude_ft;

    // GGA - Global Positioning System Fixed Data
    float nmea_longitude;
    float nmea_latitude;
    float utc_time;
    char ns, ew;
    int lock;
    int satelites;
    float hdop;
    float msl_altitude;
    char msl_units;

    // RMC - Recommended Minimmum Specific GNS Data
    char rmc_status;
    float speed_k;
    float course_d;
    int date;

    // GLL
    char gll_status;

    // VTG - Course over ground, ground speed
    float course_t; // ground speed true
    char course_t_unit;
    float course_m; // magnetic
    char course_m_unit;
    char speed_k_unit;
    float speed_km; // speek km/hr
    char speed_km_unit;
} GPS_t;

__packed struct gps_data_s{
    // GGA - Global Positioning System Fixed Data
    float longitude;
    float latitude;
    float speed_km; // speek km/hr
		uint8_t satelites;
};
typedef __packed struct gps_data_s gps_data_t;

#if (GPS_DEBUG == 1)
void GPS_print(char *data);
#endif

void GPS_Init(UART_HandleTypeDef *_huart,void (*p_data_ready_func)(gps_data_t*));
void gps_start(void);
void GSP_USBPrint(char *data);
void GPS_print_val(char *data, int value);
void GPS_UART_CallBack(void);
void GPS_UART_ErrorCallback(void);
void GPS_AbortReceiveCpltCallback(void);
int GPS_validate(char *nmeastr);
void GPS_parse(char *GPSstrParse);
void GPS_parse_ad0x0(char *GPSstrParse);
float GPS_nmea_to_dec(float deg_coord, char nsew);
GPS_t *ad0x0_get_gps_buf(void);//threads!!!!!!!!!!!!!!!!

#endif
