/**
 * @file        gps.h
 */

/* Define to prevent recursive inclusion **************************************/
#ifndef GPS_H_
#define GPS_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Includes *******************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "main.h"
#include "stm32f4xx_hal.h"
extern UART_HandleTypeDef huart3;

/* Defines ********************************************************************/
#define GPS_UART             (&huart3)
#define GPS_DMA              (&hdma_usart3_rx)
#define GPS_FLAG_PPS         1
#define GPS_FLAG_RX          2
#define GPS_FLAG_ERR         4

#define GPS_TIMEOUT          5000

#define GPS_LEN_STAMP        24  /* Length of UTC time stamp */
#define GPS_LEN_MAX          256
/* Types **********************************************************************/
/**
 * @brief   Structure of the message.
 */
#pragma pack(1)
typedef struct{
    /* UTC yy.mm.dd hh:mm:ss ab */
    uint16_t Year;
    uint8_t Month;
    uint16_t Day;
    uint8_t Hour;
    uint8_t Minute;
    uint8_t Second;
    uint8_t ParamA;
    uint8_t ParamB;
}gps_stamp_t;
#pragma pack()

/* Public functions ***********************************************************/
void GPS_GetStamp(uint8_t* timeData);
gps_stamp_t GPS_GetTimeStamp(void);
void GPS_Handler(void);
void GPS_Update(void);
void GPS_NewStamp(void);
/**
 * @brief   GPSd_Init()
 *          Initializes the GPS serial line driver.
 *
 * @return  None
 */
void GPS_Init(void);

/**
 * @brief   GPS_Error()
 *          This function must be called from the DMA error callback. It cleans
 *          the buffers and restarts the DMA reading from the UART line.
 *
 * @return  None
 */
void GPS_Error(void);

/**
 * @brief   GPS_RaiseFlag()
 *          This function switches on selected flag when specified event
 *          occurs. See GPS_FLAG_RX and GPS_FLAG_ERR. This function must
 *          be called in the UsartRX callback with GPS_FLAG_RX argument. The
 *          main GPSunication logic is done in GPSd_GetStatus function.
 *
 * @param   [in]    flag    Flag definition to raise.
 *
 * @return  None
 */
void GPS_RaiseFlag(uint16_t flag);

#ifdef __cplusplus
}
#endif

#endif /* GPS_H_ */
