GPS GMS-6 Module

Dependents:   RwSDCard_Xml_GPS

Committer:
Lucyjungz
Date:
Wed Mar 01 02:20:11 2017 +0000
Revision:
10:1311a69b0857
Parent:
8:d18d194992a9
typo baudrate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Lucyjungz 7:333d46845050 1 /**
Lucyjungz 7:333d46845050 2 ******************************************************************************
Lucyjungz 7:333d46845050 3 * @file GPSGms6.h
Lucyjungz 7:333d46845050 4 * @author Narut T
Lucyjungz 7:333d46845050 5 * @version V1
Lucyjungz 7:333d46845050 6 * @date 19/05/2016
Lucyjungz 7:333d46845050 7 * @brief Header for Library GPS GMS6
Lucyjungz 7:333d46845050 8 ******************************************************************************/
Lucyjungz 7:333d46845050 9
Lucyjungz 1:dceb4eaf697e 10 /* ############### Constant Defination ################## */
nsrwsurasak 8:d18d194992a9 11 #ifndef GPSGMS6_H
nsrwsurasak 8:d18d194992a9 12 #define GPSGMS6_H
nsrwsurasak 0:7ef27b349b37 13
Lucyjungz 4:fb1cd9893eb8 14 #define HEADER_SIZE 5 /** Header Size*/
Lucyjungz 4:fb1cd9893eb8 15 #define GPRMC_TIME_SIZE 10 /** GPRMC Time Size */
Lucyjungz 4:fb1cd9893eb8 16 #define GPRMC_STATUS_SIZE 1 /** GPRMC Status Size */
Lucyjungz 4:fb1cd9893eb8 17 #define GPRMC_LATITUDE_SIZE 9 /** GPRMC Latitude Size */
Lucyjungz 4:fb1cd9893eb8 18 #define GPRMC_LATITUDE_HEMI_SIZE 1 /** GPRMC Latitude hemi Size */
Lucyjungz 4:fb1cd9893eb8 19 #define GPRMC_LONGITUDE_SIZE 10 /** GPRMC Longitude Size */
Lucyjungz 4:fb1cd9893eb8 20 #define GPRMC_LONGITUDE_HEMI_SIZE 1 /** GPRMC Longitude hemi Size */
Lucyjungz 4:fb1cd9893eb8 21 #define GPRMC_SPEED_SIZE 5 /** GPRMC speed Size */
Lucyjungz 4:fb1cd9893eb8 22 #define GPRMC_COURSE_SIZE 5 /** GPRMC Course Size */
Lucyjungz 4:fb1cd9893eb8 23 #define GPRMC_DATE_SIZE 6 /** GPRMC Date Size */
Lucyjungz 4:fb1cd9893eb8 24 #define GPRMC_MAGNETIC_SIZE 5 /** GPRMC Magnetic Size */
Lucyjungz 4:fb1cd9893eb8 25 #define GPRMC_MAGNETIC_DIR_SIZE 1 /** GPRMC Magnetic Dir Size */
Lucyjungz 4:fb1cd9893eb8 26 #define GPRMC_INDICATOR_SIZE 1 /** GPRMC Indicator Size */
Lucyjungz 4:fb1cd9893eb8 27
Lucyjungz 4:fb1cd9893eb8 28 #define INVALID_VALUE 0xFFFF /** Invalid value */
Lucyjungz 4:fb1cd9893eb8 29 #define RX_BUF_SIZE 100 /** Receive Buffer Size */
Lucyjungz 4:fb1cd9893eb8 30
Lucyjungz 4:fb1cd9893eb8 31 #define GPS_BAUD_RATE 9600 /** GPS Baudrate*/
Lucyjungz 4:fb1cd9893eb8 32 #define GPS_STRING_BUFFER_SIZE 3 /** String conversion buffer size */
nsrwsurasak 0:7ef27b349b37 33
Lucyjungz 5:9dd9ab613497 34 #define GPS_MESSAGE_HEADER_PREFIX '$' /** Every format in GPS have this char for prefix of header */
Lucyjungz 5:9dd9ab613497 35 #define GPS_DELIMITER ',' /** Delimiter between section */
Lucyjungz 5:9dd9ab613497 36 #define GPS_DEFAULT_DATA_VALUE ' ' /** Default data value */
Lucyjungz 4:fb1cd9893eb8 37 #define GPS_TIME_SECOND_OFFSET 4 /** Second Offset in GPS Time */
Lucyjungz 4:fb1cd9893eb8 38 #define GPS_TIME_SECOND_SIZE 2 /** Second Size in GPS Time */
Lucyjungz 4:fb1cd9893eb8 39 #define GPS_TIME_MINUTE_OFFSET 2 /** Minute Offset in GPS Time */
Lucyjungz 4:fb1cd9893eb8 40 #define GPS_TIME_MINUTE_SIZE 2 /** Minute Size in GPS Time */
Lucyjungz 4:fb1cd9893eb8 41 #define GPS_TIME_HOUR_OFFSET 0 /** Hour Offset in GPS Time */
Lucyjungz 4:fb1cd9893eb8 42 #define GPS_TIME_HOUR_SIZE 2 /** Hour Size in GPS Time */
Lucyjungz 4:fb1cd9893eb8 43 #define GPS_TIME_DATE_OFFSET 0 /** Date Offset in GPS Date */
Lucyjungz 4:fb1cd9893eb8 44 #define GPS_TIME_DATE_SIZE 2 /** Date Size in GPS Date */
Lucyjungz 4:fb1cd9893eb8 45 #define GPS_TIME_MONTH_OFFSET 2 /** Month Offset in GPS Date */
Lucyjungz 4:fb1cd9893eb8 46 #define GPS_TIME_MONTH_SIZE 2 /** Month Size in GPS Date */
Lucyjungz 4:fb1cd9893eb8 47 #define GPS_TIME_YEAR_OFFSET 4 /** Year Offset in GPS Date */
Lucyjungz 4:fb1cd9893eb8 48 #define GPS_TIME_YEAR_SIZE 2 /** Year Size in GPS Date */
nsrwsurasak 0:7ef27b349b37 49
Lucyjungz 4:fb1cd9893eb8 50 #define INVALID_TIME_DATE 0 /** Invalid date value */
Lucyjungz 4:fb1cd9893eb8 51 #define INVALID_TIME_MONTH 0 /** Invalid month value */
Lucyjungz 4:fb1cd9893eb8 52 #define INVALID_TIME_YEAR 0 /** Invalid year value */
Lucyjungz 4:fb1cd9893eb8 53
Lucyjungz 4:fb1cd9893eb8 54 /* ############### Method Defination ################## */
Lucyjungz 6:5e30784ffd54 55 /** @brief Check if the indicator is valid
Lucyjungz 6:5e30784ffd54 56 * @param indicator - a char that represent the indicator message
Lucyjungz 6:5e30784ffd54 57 * @retval True - if indicator is valid , otherwise, false .
Lucyjungz 6:5e30784ffd54 58 */
Lucyjungz 4:fb1cd9893eb8 59 #define IS_INDICATOR_VALID(indicator) ((indicator == (char)'A') || (indicator == (char)'D')|| (indicator == (char)'E'))
Lucyjungz 6:5e30784ffd54 60
Lucyjungz 6:5e30784ffd54 61 /** @brief Check header is GPRMC header
Lucyjungz 6:5e30784ffd54 62 * @param pointer to char array that contain message
Lucyjungz 6:5e30784ffd54 63 * @retval True - if header is GPRMC , otherwise, false.
Lucyjungz 6:5e30784ffd54 64 */
Lucyjungz 6:5e30784ffd54 65 #define IS_HEADER_GPRPC(buf) (buf[index] == 'G' && \
Lucyjungz 6:5e30784ffd54 66 buf[index+1] == 'P' && \
Lucyjungz 6:5e30784ffd54 67 buf[index+2] == 'R' && \
Lucyjungz 6:5e30784ffd54 68 buf[index+3] == 'M' && \
Lucyjungz 6:5e30784ffd54 69 buf[index+4] == 'C' )
Lucyjungz 4:fb1cd9893eb8 70
nsrwsurasak 0:7ef27b349b37 71
Lucyjungz 1:dceb4eaf697e 72 /* ############### Enum ################## */
nsrwsurasak 0:7ef27b349b37 73 typedef enum GPS_ProcessState {
Lucyjungz 4:fb1cd9893eb8 74 GPS_Process_Start = 0, /** State Start processing */
Lucyjungz 4:fb1cd9893eb8 75 GPS_Process_Header, /** State process header */
Lucyjungz 4:fb1cd9893eb8 76 GPS_Process_Time, /** State process Time */
Lucyjungz 4:fb1cd9893eb8 77 GPS_Process_Status, /** State process status */
Lucyjungz 4:fb1cd9893eb8 78 GPS_Process_Latitude, /** State process Latitude */
Lucyjungz 4:fb1cd9893eb8 79 GPS_Process_Latitude_hemis, /** State process Latitude hemis */
Lucyjungz 4:fb1cd9893eb8 80 GPS_Process_Longitude, /** State process Longitude */
Lucyjungz 4:fb1cd9893eb8 81 GPS_Process_Longitude_hemis, /** State process Longitude hemis */
Lucyjungz 4:fb1cd9893eb8 82 GPS_Process_Speed, /** State process Speed */
Lucyjungz 4:fb1cd9893eb8 83 GPS_Process_Course, /** State process Course */
Lucyjungz 4:fb1cd9893eb8 84 GPS_Process_Date, /** State process Date */
Lucyjungz 4:fb1cd9893eb8 85 GPS_Process_Magnetic, /** State process Magnetic */
Lucyjungz 4:fb1cd9893eb8 86 GPS_Process_Magnetic_Dir, /** State process Magnetic Dir */
Lucyjungz 4:fb1cd9893eb8 87 GPS_Process_Indicator, /** State process Indicator */
Lucyjungz 4:fb1cd9893eb8 88 GPS_Process_Complete , /** State process Complete */
Lucyjungz 4:fb1cd9893eb8 89 GPS_Process_SIZE /** NUMBER OF STATEs */
nsrwsurasak 0:7ef27b349b37 90 } GPS_ProcessState;
nsrwsurasak 0:7ef27b349b37 91
nsrwsurasak 0:7ef27b349b37 92 typedef enum GPS_ProcessStatus {
Lucyjungz 4:fb1cd9893eb8 93 GPS_Status_Valid, /** Status valid */
Lucyjungz 4:fb1cd9893eb8 94 GPS_Status_Empty, /** Status data is empty */
Lucyjungz 4:fb1cd9893eb8 95 GPS_Status_NotEnough, /** Status Receive Buffer is not enough to process */
nsrwsurasak 0:7ef27b349b37 96 } GPS_ProcessStatus;
nsrwsurasak 0:7ef27b349b37 97
Lucyjungz 1:dceb4eaf697e 98
Lucyjungz 1:dceb4eaf697e 99 /* ############### Structure ################## */
Lucyjungz 1:dceb4eaf697e 100 typedef struct {
Lucyjungz 4:fb1cd9893eb8 101 char header[HEADER_SIZE+1]; /** Specific section for header data */
Lucyjungz 4:fb1cd9893eb8 102 char time[GPRMC_TIME_SIZE+1]; /** Specific section for time data */
Lucyjungz 4:fb1cd9893eb8 103 char status[GPRMC_STATUS_SIZE+1]; /** Specific section for status data */
Lucyjungz 4:fb1cd9893eb8 104 char latitude[GPRMC_LATITUDE_SIZE+1]; /** Specific section for latitude data */
Lucyjungz 4:fb1cd9893eb8 105 char latitude_hemi[GPRMC_LATITUDE_HEMI_SIZE+1]; /** Specific section for latitude hemi data */
Lucyjungz 4:fb1cd9893eb8 106 char longitude[GPRMC_LONGITUDE_SIZE+1]; /** Specific section for longitude data */
Lucyjungz 4:fb1cd9893eb8 107 char longitude_hemi[GPRMC_LATITUDE_HEMI_SIZE+1]; /** Specific section for longitude hemi data */
Lucyjungz 4:fb1cd9893eb8 108 char speed[GPRMC_SPEED_SIZE+1]; /** Specific section for speed data */
Lucyjungz 4:fb1cd9893eb8 109 char course[GPRMC_COURSE_SIZE+1]; /** Specific section for Course data */
Lucyjungz 4:fb1cd9893eb8 110 char date[GPRMC_DATE_SIZE+1]; /** Specific section for Date data */
Lucyjungz 4:fb1cd9893eb8 111 char magnetic[GPRMC_MAGNETIC_SIZE+1]; /** Specific section for Magnetic data */
Lucyjungz 4:fb1cd9893eb8 112 char magnetic_dir[GPRMC_MAGNETIC_DIR_SIZE+1]; /** Specific section for Magnetic dir data */
Lucyjungz 4:fb1cd9893eb8 113 char indicator[GPRMC_INDICATOR_SIZE+1]; /** Specific section for Indicator data */
Lucyjungz 1:dceb4eaf697e 114 } GPRMC_Data_TypeDef;
Lucyjungz 1:dceb4eaf697e 115
Lucyjungz 1:dceb4eaf697e 116
nsrwsurasak 0:7ef27b349b37 117 typedef struct {
Lucyjungz 4:fb1cd9893eb8 118 GPS_ProcessState state; /** indicate index of the table */
Lucyjungz 4:fb1cd9893eb8 119 int size; /** section size */
Lucyjungz 4:fb1cd9893eb8 120 char * p_val; /** pointer to variable to be store */
nsrwsurasak 0:7ef27b349b37 121 } GPRMC_Tbl_TypeDef;
nsrwsurasak 0:7ef27b349b37 122
nsrwsurasak 0:7ef27b349b37 123
Lucyjungz 1:dceb4eaf697e 124 /* ############### Class ################## */
nsrwsurasak 0:7ef27b349b37 125 class GPSGms6
nsrwsurasak 0:7ef27b349b37 126 {
nsrwsurasak 0:7ef27b349b37 127 public:
nsrwsurasak 0:7ef27b349b37 128
Lucyjungz 1:dceb4eaf697e 129 /**
Lucyjungz 1:dceb4eaf697e 130 * Constructor
Lucyjungz 1:dceb4eaf697e 131 */
nsrwsurasak 0:7ef27b349b37 132 GPSGms6();
nsrwsurasak 0:7ef27b349b37 133
Lucyjungz 1:dceb4eaf697e 134 /**
Lucyjungz 1:dceb4eaf697e 135 * Start GPS
Lucyjungz 1:dceb4eaf697e 136 */
nsrwsurasak 0:7ef27b349b37 137 void start_GPS();
Lucyjungz 1:dceb4eaf697e 138
Lucyjungz 1:dceb4eaf697e 139 /**
Lucyjungz 1:dceb4eaf697e 140 * Get UTC Time
Lucyjungz 1:dceb4eaf697e 141 * @returns
Lucyjungz 1:dceb4eaf697e 142 * UTC Time
Lucyjungz 1:dceb4eaf697e 143 */
nsrwsurasak 0:7ef27b349b37 144 tm UTCTime();
nsrwsurasak 0:7ef27b349b37 145 /** Get Latest GPRMC Data
nsrwsurasak 0:7ef27b349b37 146 *
nsrwsurasak 0:7ef27b349b37 147 * @returns
nsrwsurasak 0:7ef27b349b37 148 * Latest GPRMC Data
nsrwsurasak 0:7ef27b349b37 149 */
Lucyjungz 7:333d46845050 150 GPRMC_Data_TypeDef * latestGPRMC();
nsrwsurasak 0:7ef27b349b37 151
nsrwsurasak 0:7ef27b349b37 152 /** Get Valid Data Interval
nsrwsurasak 0:7ef27b349b37 153 *
nsrwsurasak 0:7ef27b349b37 154 * @returns
nsrwsurasak 0:7ef27b349b37 155 * Valid Data Interval
nsrwsurasak 0:7ef27b349b37 156 */
Lucyjungz 7:333d46845050 157 GPRMC_Data_TypeDef * validGPRMC();
nsrwsurasak 0:7ef27b349b37 158
nsrwsurasak 0:7ef27b349b37 159 /** Get availability of gprmc
nsrwsurasak 0:7ef27b349b37 160 *
nsrwsurasak 0:7ef27b349b37 161 * @returns
nsrwsurasak 0:7ef27b349b37 162 * 'true' - if data is available
nsrwsurasak 0:7ef27b349b37 163 */
nsrwsurasak 0:7ef27b349b37 164 bool available();
nsrwsurasak 0:7ef27b349b37 165
nsrwsurasak 0:7ef27b349b37 166
nsrwsurasak 0:7ef27b349b37 167 private:
nsrwsurasak 0:7ef27b349b37 168
nsrwsurasak 8:d18d194992a9 169 };
nsrwsurasak 8:d18d194992a9 170
nsrwsurasak 8:d18d194992a9 171 #endif