GPS GMS-6 Module

Dependents:   RwSDCard_Xml_GPS

Committer:
Lucyjungz
Date:
Thu May 19 10:44:48 2016 +0000
Revision:
7:333d46845050
Parent:
6:5e30784ffd54
Child:
8:d18d194992a9
Update Comments

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