GPS GMS-6 Module

Dependents:   RwSDCard_Xml_GPS

Committer:
Lucyjungz
Date:
Wed May 18 17:28:10 2016 +0000
Revision:
5:9dd9ab613497
Parent:
4:fb1cd9893eb8
Child:
7:333d46845050
Add more comments and constant

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nsrwsurasak 0:7ef27b349b37 1 #include "mbed.h"
nsrwsurasak 0:7ef27b349b37 2 #include "GPSGms6.h"
nsrwsurasak 0:7ef27b349b37 3 #include <string>
nsrwsurasak 0:7ef27b349b37 4
Lucyjungz 1:dceb4eaf697e 5
Lucyjungz 1:dceb4eaf697e 6 /* ############### Method Defination ################## */
nsrwsurasak 0:7ef27b349b37 7 #define GET_GPRMC_SECTION_SIZE(state) (unsigned int)gprms_tbl[state].size
nsrwsurasak 0:7ef27b349b37 8 #define GET_GPRMC_VARIABLE_ADDR(state) gprms_tbl[state].p_val
nsrwsurasak 0:7ef27b349b37 9 #define GET_GPRMC_NEXT_STATE(state) (GPS_ProcessState)gprms_tbl[state+1].state
nsrwsurasak 0:7ef27b349b37 10
nsrwsurasak 0:7ef27b349b37 11
Lucyjungz 1:dceb4eaf697e 12 GPRMC_Data_TypeDef m_gprmc; // Latest GPRMC data
Lucyjungz 1:dceb4eaf697e 13 GPRMC_Data_TypeDef m_valid_gprmc; // Latest valid GPRMC Data
Lucyjungz 1:dceb4eaf697e 14 char m_RxBuf[RX_BUF_SIZE]; // Reading Buffer
Lucyjungz 1:dceb4eaf697e 15 bool m_available; // Flag to indicate availability of GPRMC data
Lucyjungz 1:dceb4eaf697e 16 int m_index; // an index
Lucyjungz 1:dceb4eaf697e 17
Lucyjungz 1:dceb4eaf697e 18 /**
Lucyjungz 1:dceb4eaf697e 19 * Initializaion of the GPS Module by using serial and selected PIN
Lucyjungz 1:dceb4eaf697e 20 */
nsrwsurasak 0:7ef27b349b37 21 Serial serial_gps(PA_9, PA_10);
Lucyjungz 1:dceb4eaf697e 22
Lucyjungz 1:dceb4eaf697e 23 /**
Lucyjungz 1:dceb4eaf697e 24 * Table for GPRMC structure that use for decoding GPRMC message of the GPS
Lucyjungz 1:dceb4eaf697e 25 * This table contain 3 element which are index, section size and pointer to variable
Lucyjungz 1:dceb4eaf697e 26 * Once GPS process routine is called data will be populated in variable that define in third column
Lucyjungz 1:dceb4eaf697e 27 */
nsrwsurasak 0:7ef27b349b37 28 GPRMC_Tbl_TypeDef gprms_tbl[] = {
Lucyjungz 1:dceb4eaf697e 29 // index , section size , variable
nsrwsurasak 0:7ef27b349b37 30 {GPS_Process_Start , INVALID_VALUE ,(char *)INVALID_VALUE},
nsrwsurasak 0:7ef27b349b37 31 {GPS_Process_Header , HEADER_SIZE , m_gprmc.header},
nsrwsurasak 0:7ef27b349b37 32 {GPS_Process_Time , GPRMC_TIME_SIZE , m_gprmc.time},
nsrwsurasak 0:7ef27b349b37 33 {GPS_Process_Status , GPRMC_STATUS_SIZE , m_gprmc.status},
nsrwsurasak 0:7ef27b349b37 34 {GPS_Process_Latitude , GPRMC_LATITUDE_SIZE , m_gprmc.latitude},
nsrwsurasak 0:7ef27b349b37 35 {GPS_Process_Latitude_hemis , GPRMC_LATITUDE_HEMI_SIZE , m_gprmc.latitude_hemi},
nsrwsurasak 0:7ef27b349b37 36 {GPS_Process_Longitude , GPRMC_LONGITUDE_SIZE , m_gprmc.longitude},
nsrwsurasak 0:7ef27b349b37 37 {GPS_Process_Longitude_hemis , GPRMC_LONGITUDE_HEMI_SIZE , m_gprmc.longitude_hemi},
nsrwsurasak 0:7ef27b349b37 38 {GPS_Process_Speed , GPRMC_SPEED_SIZE , m_gprmc.speed},
nsrwsurasak 0:7ef27b349b37 39 {GPS_Process_Course , GPRMC_COURSE_SIZE , m_gprmc.course},
nsrwsurasak 0:7ef27b349b37 40 {GPS_Process_Date , GPRMC_DATE_SIZE , m_gprmc.date},
nsrwsurasak 0:7ef27b349b37 41 {GPS_Process_Magnetic , GPRMC_MAGNETIC_SIZE , m_gprmc.magnetic},
nsrwsurasak 0:7ef27b349b37 42 {GPS_Process_Magnetic_Dir , GPRMC_MAGNETIC_DIR_SIZE , m_gprmc.magnetic_dir},
nsrwsurasak 0:7ef27b349b37 43 {GPS_Process_Indicator , GPRMC_INDICATOR_SIZE , m_gprmc.indicator},
nsrwsurasak 0:7ef27b349b37 44 {GPS_Process_Complete ,INVALID_VALUE ,(char *)INVALID_VALUE}
nsrwsurasak 0:7ef27b349b37 45
nsrwsurasak 0:7ef27b349b37 46 };
Lucyjungz 1:dceb4eaf697e 47
Lucyjungz 1:dceb4eaf697e 48 /**
Lucyjungz 1:dceb4eaf697e 49 * @brief Utility for processing GPRMC message from the GPS
Lucyjungz 1:dceb4eaf697e 50 * @note
Lucyjungz 1:dceb4eaf697e 51 * @param state : current state that program is processing
Lucyjungz 1:dceb4eaf697e 52 * @param buf : pointer to buffer that supposed to have GPS message
Lucyjungz 1:dceb4eaf697e 53 * @param buf index : index to the current offset of the buffer
Lucyjungz 1:dceb4eaf697e 54 * @param buf size : size of the buffer
Lucyjungz 1:dceb4eaf697e 55 * @param section size : size of the processing section
Lucyjungz 1:dceb4eaf697e 56 * @retval pointer of return value
Lucyjungz 1:dceb4eaf697e 57 */
Lucyjungz 2:3064a132bc39 58 static GPS_ProcessStatus GPSGms6_ProcessGprmcSection(GPS_ProcessState state,char * buf , unsigned int buf_index,unsigned int buf_size, unsigned int section_size, char * ret_value)
nsrwsurasak 0:7ef27b349b37 59 {
Lucyjungz 1:dceb4eaf697e 60 /* Initialize status */
nsrwsurasak 0:7ef27b349b37 61 GPS_ProcessStatus status = GPS_Status_Valid;
Lucyjungz 1:dceb4eaf697e 62 if (buf_index >= (buf_size - section_size))
Lucyjungz 1:dceb4eaf697e 63 {
Lucyjungz 1:dceb4eaf697e 64 /* Data not Enough to process */
nsrwsurasak 0:7ef27b349b37 65 status = GPS_Status_NotEnough;
Lucyjungz 1:dceb4eaf697e 66 }
Lucyjungz 5:9dd9ab613497 67 else if (buf[buf_index] == GPS_DELIMITER)
Lucyjungz 1:dceb4eaf697e 68 {
Lucyjungz 1:dceb4eaf697e 69 /* Empty Data */
nsrwsurasak 0:7ef27b349b37 70 status = GPS_Status_Empty;
Lucyjungz 5:9dd9ab613497 71 memset(ret_value,GPS_DEFAULT_DATA_VALUE, section_size);
Lucyjungz 1:dceb4eaf697e 72 }
Lucyjungz 1:dceb4eaf697e 73 else
Lucyjungz 1:dceb4eaf697e 74 {
Lucyjungz 1:dceb4eaf697e 75 /* Populate the data */
nsrwsurasak 0:7ef27b349b37 76 unsigned int idx;
nsrwsurasak 0:7ef27b349b37 77 for(idx = 0; idx < section_size; idx++) {
nsrwsurasak 0:7ef27b349b37 78 ret_value[idx] = buf[buf_index + idx];
nsrwsurasak 0:7ef27b349b37 79 }
nsrwsurasak 0:7ef27b349b37 80
nsrwsurasak 0:7ef27b349b37 81 }
Lucyjungz 1:dceb4eaf697e 82
Lucyjungz 1:dceb4eaf697e 83 /* Return status */
nsrwsurasak 0:7ef27b349b37 84 return status;
nsrwsurasak 0:7ef27b349b37 85
nsrwsurasak 0:7ef27b349b37 86 }
Lucyjungz 1:dceb4eaf697e 87 /**
Lucyjungz 1:dceb4eaf697e 88 * @brief Utility for processing GPS data
Lucyjungz 1:dceb4eaf697e 89 * @note this rely on gprmc table
Lucyjungz 1:dceb4eaf697e 90 * @param buf : pointer to buffer that supposed to have GPS message
Lucyjungz 1:dceb4eaf697e 91 * @param buf size : size of the buffer
Lucyjungz 1:dceb4eaf697e 92 * @retval variable that define in the table will be populated the data
Lucyjungz 1:dceb4eaf697e 93 */
Lucyjungz 2:3064a132bc39 94 static void GPSGms6_ProcessGpsData(char * buf, unsigned int size)
nsrwsurasak 0:7ef27b349b37 95 {
nsrwsurasak 0:7ef27b349b37 96 unsigned int index;
nsrwsurasak 0:7ef27b349b37 97 unsigned int adv_index = 0;
Lucyjungz 1:dceb4eaf697e 98
Lucyjungz 1:dceb4eaf697e 99 /* Initialize status and state */
nsrwsurasak 0:7ef27b349b37 100 GPS_ProcessStatus status = GPS_Status_Valid;
nsrwsurasak 0:7ef27b349b37 101 GPS_ProcessState state = GPS_Process_Start;
Lucyjungz 1:dceb4eaf697e 102
Lucyjungz 1:dceb4eaf697e 103 /* Walk through the buffer */
Lucyjungz 1:dceb4eaf697e 104 for(index = 0; index < size; index++)
Lucyjungz 1:dceb4eaf697e 105 {
Lucyjungz 1:dceb4eaf697e 106 /* Start the process */
Lucyjungz 1:dceb4eaf697e 107 if (state == GPS_Process_Start)
Lucyjungz 1:dceb4eaf697e 108 {
Lucyjungz 1:dceb4eaf697e 109 /* Process the message */
Lucyjungz 5:9dd9ab613497 110 if (buf[index] == GPS_MESSAGE_HEADER_PREFIX)
Lucyjungz 1:dceb4eaf697e 111 {
Lucyjungz 1:dceb4eaf697e 112 /* Found header */
nsrwsurasak 0:7ef27b349b37 113 state = GPS_Process_Header;
Lucyjungz 1:dceb4eaf697e 114 }
Lucyjungz 1:dceb4eaf697e 115 else
Lucyjungz 1:dceb4eaf697e 116 {
Lucyjungz 1:dceb4eaf697e 117 /* Continue searching */
nsrwsurasak 0:7ef27b349b37 118 continue;
nsrwsurasak 0:7ef27b349b37 119 }
Lucyjungz 1:dceb4eaf697e 120 }
Lucyjungz 1:dceb4eaf697e 121 else if (state == GPS_Process_Header)
Lucyjungz 1:dceb4eaf697e 122 {
Lucyjungz 1:dceb4eaf697e 123 /* Process Header */
Lucyjungz 1:dceb4eaf697e 124 if (index < (size - HEADER_SIZE))
Lucyjungz 1:dceb4eaf697e 125 {
Lucyjungz 1:dceb4eaf697e 126 /* Check for GPRMC */
Lucyjungz 4:fb1cd9893eb8 127 if (IS_HEADER_GPRPC(buf))
Lucyjungz 4:fb1cd9893eb8 128 {
Lucyjungz 1:dceb4eaf697e 129
Lucyjungz 1:dceb4eaf697e 130 /* Populate the header to the variable */
nsrwsurasak 0:7ef27b349b37 131 unsigned int h_index;
Lucyjungz 4:fb1cd9893eb8 132 for(h_index = 0; h_index < HEADER_SIZE; h_index++)
Lucyjungz 4:fb1cd9893eb8 133 {
nsrwsurasak 0:7ef27b349b37 134 m_gprmc.header[h_index] = buf[index + h_index];
nsrwsurasak 0:7ef27b349b37 135 }
Lucyjungz 1:dceb4eaf697e 136
Lucyjungz 1:dceb4eaf697e 137 /* Move to the next section */
nsrwsurasak 0:7ef27b349b37 138 index += HEADER_SIZE;
nsrwsurasak 0:7ef27b349b37 139 state = GPS_Process_Time;
nsrwsurasak 0:7ef27b349b37 140 }
Lucyjungz 1:dceb4eaf697e 141 }
Lucyjungz 1:dceb4eaf697e 142 else
Lucyjungz 1:dceb4eaf697e 143 {
nsrwsurasak 0:7ef27b349b37 144 break;
nsrwsurasak 0:7ef27b349b37 145 }
nsrwsurasak 0:7ef27b349b37 146
Lucyjungz 1:dceb4eaf697e 147 }
Lucyjungz 1:dceb4eaf697e 148 else
Lucyjungz 1:dceb4eaf697e 149 {
Lucyjungz 1:dceb4eaf697e 150 /* Process GRPMC section */
Lucyjungz 2:3064a132bc39 151 status = GPSGms6_ProcessGprmcSection(state, buf ,index, size, GET_GPRMC_SECTION_SIZE(state), GET_GPRMC_VARIABLE_ADDR(state));
Lucyjungz 1:dceb4eaf697e 152
Lucyjungz 1:dceb4eaf697e 153 /* Move to the next section */
nsrwsurasak 0:7ef27b349b37 154 adv_index = GET_GPRMC_SECTION_SIZE(state);
nsrwsurasak 0:7ef27b349b37 155 state = GET_GPRMC_NEXT_STATE(state) ;
nsrwsurasak 0:7ef27b349b37 156 }
nsrwsurasak 0:7ef27b349b37 157
nsrwsurasak 0:7ef27b349b37 158
Lucyjungz 1:dceb4eaf697e 159 if (status == GPS_Status_NotEnough || state == GPS_Process_Complete)
Lucyjungz 1:dceb4eaf697e 160 {
Lucyjungz 1:dceb4eaf697e 161 /* In case of status not normal, then done */
nsrwsurasak 0:7ef27b349b37 162 break;
Lucyjungz 1:dceb4eaf697e 163 }
Lucyjungz 1:dceb4eaf697e 164 else if (status == GPS_Status_Valid)
Lucyjungz 1:dceb4eaf697e 165 {
Lucyjungz 1:dceb4eaf697e 166 /* Status is valid, move on */
nsrwsurasak 0:7ef27b349b37 167 index += adv_index;
nsrwsurasak 0:7ef27b349b37 168 }
nsrwsurasak 0:7ef27b349b37 169 }
nsrwsurasak 0:7ef27b349b37 170
Lucyjungz 1:dceb4eaf697e 171 /* Check validity of the data */
Lucyjungz 4:fb1cd9893eb8 172 if (IS_INDICATOR_VALID(m_gprmc.indicator[0]))
Lucyjungz 1:dceb4eaf697e 173 {
Lucyjungz 1:dceb4eaf697e 174 /* If valid, populate to the valid variable */
nsrwsurasak 0:7ef27b349b37 175 m_available= true;
nsrwsurasak 0:7ef27b349b37 176 memcpy(&m_valid_gprmc, &m_gprmc , sizeof(m_gprmc));
nsrwsurasak 0:7ef27b349b37 177 }
nsrwsurasak 0:7ef27b349b37 178 }
nsrwsurasak 0:7ef27b349b37 179
Lucyjungz 1:dceb4eaf697e 180 /**
Lucyjungz 1:dceb4eaf697e 181 * @brief Callback function that process when the message is completed
Lucyjungz 1:dceb4eaf697e 182 * @note Rx Serial Interrupt must be properly started
Lucyjungz 1:dceb4eaf697e 183 * @retval
Lucyjungz 1:dceb4eaf697e 184 */
nsrwsurasak 0:7ef27b349b37 185 void complete_callback()
nsrwsurasak 0:7ef27b349b37 186 {
Lucyjungz 1:dceb4eaf697e 187 /* Process GPS Data once message is completed read */
Lucyjungz 2:3064a132bc39 188 GPSGms6_ProcessGpsData(m_RxBuf, RX_BUF_SIZE);
nsrwsurasak 0:7ef27b349b37 189 }
Lucyjungz 1:dceb4eaf697e 190 /**
Lucyjungz 1:dceb4eaf697e 191 * @brief Callback function that process when a charector is transfered
Lucyjungz 1:dceb4eaf697e 192 * @note Rx Serial Interrupt must be properly started
Lucyjungz 1:dceb4eaf697e 193 * @retval
Lucyjungz 1:dceb4eaf697e 194 */
nsrwsurasak 0:7ef27b349b37 195 void byte_callback()
nsrwsurasak 0:7ef27b349b37 196 {
Lucyjungz 1:dceb4eaf697e 197 /* Note: you need to actually read from the serial to clear the RX interrupt */
nsrwsurasak 0:7ef27b349b37 198 m_RxBuf[m_index] = serial_gps.getc();
nsrwsurasak 0:7ef27b349b37 199 m_index++;
Lucyjungz 1:dceb4eaf697e 200 if (m_index == RX_BUF_SIZE)
Lucyjungz 1:dceb4eaf697e 201 {
Lucyjungz 1:dceb4eaf697e 202 /* Buffer is full, call complete callback */
nsrwsurasak 0:7ef27b349b37 203 m_index = 0;
nsrwsurasak 0:7ef27b349b37 204 complete_callback();
nsrwsurasak 0:7ef27b349b37 205 }
nsrwsurasak 0:7ef27b349b37 206 }
Lucyjungz 1:dceb4eaf697e 207
Lucyjungz 1:dceb4eaf697e 208
Lucyjungz 1:dceb4eaf697e 209 /**
Lucyjungz 1:dceb4eaf697e 210 * @brief Constructor for GPS module
Lucyjungz 1:dceb4eaf697e 211 * @note
Lucyjungz 1:dceb4eaf697e 212 * @retval
Lucyjungz 1:dceb4eaf697e 213 */
nsrwsurasak 0:7ef27b349b37 214 GPSGms6::GPSGms6()
nsrwsurasak 0:7ef27b349b37 215 {
nsrwsurasak 0:7ef27b349b37 216
nsrwsurasak 0:7ef27b349b37 217 m_index = 0;
nsrwsurasak 0:7ef27b349b37 218 m_available = false;
nsrwsurasak 0:7ef27b349b37 219
Lucyjungz 1:dceb4eaf697e 220 /* Talking on 9600 bps */
Lucyjungz 4:fb1cd9893eb8 221 serial_gps.baud(GPS_BAUD_RATE);
nsrwsurasak 0:7ef27b349b37 222
nsrwsurasak 0:7ef27b349b37 223 }
Lucyjungz 1:dceb4eaf697e 224
Lucyjungz 1:dceb4eaf697e 225 /**
Lucyjungz 1:dceb4eaf697e 226 * @brief Function to start GPS Module
Lucyjungz 1:dceb4eaf697e 227 * @note after started, interrupt will always be active
Lucyjungz 1:dceb4eaf697e 228 * @retval
Lucyjungz 1:dceb4eaf697e 229 */
nsrwsurasak 0:7ef27b349b37 230 void GPSGms6::start_GPS()
nsrwsurasak 0:7ef27b349b37 231 {
Lucyjungz 1:dceb4eaf697e 232 /* Start Rx interrupt */
nsrwsurasak 0:7ef27b349b37 233 serial_gps.attach(&byte_callback);
nsrwsurasak 0:7ef27b349b37 234 }
Lucyjungz 1:dceb4eaf697e 235
Lucyjungz 1:dceb4eaf697e 236 /**
Lucyjungz 1:dceb4eaf697e 237 * @brief Function to get latest GPRMC data
Lucyjungz 1:dceb4eaf697e 238 * @note
Lucyjungz 1:dceb4eaf697e 239 * @retval latest GPRMC data
Lucyjungz 1:dceb4eaf697e 240 */
nsrwsurasak 0:7ef27b349b37 241 GPRMC_Data_TypeDef GPSGms6::latestGPRMC()
nsrwsurasak 0:7ef27b349b37 242 {
nsrwsurasak 0:7ef27b349b37 243 return (m_gprmc);
nsrwsurasak 0:7ef27b349b37 244 }
Lucyjungz 1:dceb4eaf697e 245 /**
Lucyjungz 1:dceb4eaf697e 246 * @brief Function to get latest and valid GPRMC
Lucyjungz 1:dceb4eaf697e 247 * @note
Lucyjungz 1:dceb4eaf697e 248 * @retval valid GPRMC data
Lucyjungz 1:dceb4eaf697e 249 */
nsrwsurasak 0:7ef27b349b37 250 GPRMC_Data_TypeDef GPSGms6::validGPRMC()
nsrwsurasak 0:7ef27b349b37 251 {
nsrwsurasak 0:7ef27b349b37 252 m_available = false;
nsrwsurasak 0:7ef27b349b37 253 return (m_valid_gprmc);
nsrwsurasak 0:7ef27b349b37 254 }
Lucyjungz 1:dceb4eaf697e 255
Lucyjungz 1:dceb4eaf697e 256 /**
Lucyjungz 1:dceb4eaf697e 257 * @brief Function to get available flag of the valid GPRMC data
Lucyjungz 1:dceb4eaf697e 258 * @note
Lucyjungz 1:dceb4eaf697e 259 * @retval latest GPRMC data
Lucyjungz 1:dceb4eaf697e 260 */
nsrwsurasak 0:7ef27b349b37 261 bool GPSGms6::available()
nsrwsurasak 0:7ef27b349b37 262 {
nsrwsurasak 0:7ef27b349b37 263 return (m_available);
nsrwsurasak 0:7ef27b349b37 264 }
Lucyjungz 1:dceb4eaf697e 265 /**
Lucyjungz 1:dceb4eaf697e 266 * @brief Function to get UTC time
Lucyjungz 1:dceb4eaf697e 267 * @note
Lucyjungz 1:dceb4eaf697e 268 * @retval UTC time tn fm struct format
Lucyjungz 1:dceb4eaf697e 269 */
nsrwsurasak 0:7ef27b349b37 270 tm GPSGms6::UTCTime()
nsrwsurasak 0:7ef27b349b37 271 {
nsrwsurasak 0:7ef27b349b37 272 struct tm t;
Lucyjungz 1:dceb4eaf697e 273
Lucyjungz 1:dceb4eaf697e 274 /* Check available of date and time */
Lucyjungz 4:fb1cd9893eb8 275 if (m_gprmc.date[GPS_TIME_DATE_OFFSET] != ' ' && m_gprmc.time[GPS_TIME_HOUR_OFFSET] != ' ' )
nsrwsurasak 0:7ef27b349b37 276 {
Lucyjungz 1:dceb4eaf697e 277
Lucyjungz 1:dceb4eaf697e 278 /* Allocate buffer for buffering */
Lucyjungz 4:fb1cd9893eb8 279 char str[GPS_STRING_BUFFER_SIZE];
nsrwsurasak 0:7ef27b349b37 280
Lucyjungz 1:dceb4eaf697e 281 /* populate the second */
Lucyjungz 4:fb1cd9893eb8 282 memcpy( str, &m_gprmc.time[GPS_TIME_SECOND_OFFSET], GPS_TIME_SECOND_SIZE );
nsrwsurasak 0:7ef27b349b37 283 t.tm_sec = atoi(str);
Lucyjungz 1:dceb4eaf697e 284
Lucyjungz 1:dceb4eaf697e 285 /* populate the minute */
Lucyjungz 4:fb1cd9893eb8 286 memcpy( str, &m_gprmc.time[GPS_TIME_MINUTE_OFFSET], GPS_TIME_MINUTE_SIZE );
nsrwsurasak 0:7ef27b349b37 287 t.tm_min = atoi(str);
Lucyjungz 1:dceb4eaf697e 288
Lucyjungz 1:dceb4eaf697e 289 /* populate the hour */
Lucyjungz 4:fb1cd9893eb8 290 memcpy( str, &m_gprmc.time[GPS_TIME_HOUR_OFFSET], GPS_TIME_HOUR_SIZE );
nsrwsurasak 0:7ef27b349b37 291 t.tm_hour = atoi(str);
nsrwsurasak 0:7ef27b349b37 292
Lucyjungz 1:dceb4eaf697e 293 /* populate the date */
Lucyjungz 4:fb1cd9893eb8 294 memcpy( str, &m_gprmc.date[GPS_TIME_DATE_OFFSET], GPS_TIME_DATE_SIZE );
nsrwsurasak 0:7ef27b349b37 295 t.tm_mday = atoi(str);
nsrwsurasak 0:7ef27b349b37 296
Lucyjungz 1:dceb4eaf697e 297 /* populate the month */
Lucyjungz 4:fb1cd9893eb8 298 memcpy( str, &m_gprmc.date[GPS_TIME_MONTH_OFFSET], GPS_TIME_MONTH_SIZE );
nsrwsurasak 0:7ef27b349b37 299 t.tm_mon = atoi(str);
nsrwsurasak 0:7ef27b349b37 300
Lucyjungz 1:dceb4eaf697e 301 /* populate the year */
Lucyjungz 4:fb1cd9893eb8 302 memcpy( str, &m_gprmc.date[GPS_TIME_YEAR_OFFSET], GPS_TIME_YEAR_SIZE );
nsrwsurasak 0:7ef27b349b37 303 t.tm_year = atoi(str);
nsrwsurasak 0:7ef27b349b37 304 }
nsrwsurasak 0:7ef27b349b37 305 else
nsrwsurasak 0:7ef27b349b37 306 {
Lucyjungz 1:dceb4eaf697e 307 /* Found nothing */
Lucyjungz 4:fb1cd9893eb8 308 t.tm_mday = INVALID_TIME_DATE;
Lucyjungz 4:fb1cd9893eb8 309 t.tm_mon = INVALID_TIME_MONTH;
Lucyjungz 4:fb1cd9893eb8 310 t.tm_year = INVALID_TIME_YEAR;
nsrwsurasak 0:7ef27b349b37 311 }
Lucyjungz 1:dceb4eaf697e 312
Lucyjungz 1:dceb4eaf697e 313 /* Return the time !! */
nsrwsurasak 0:7ef27b349b37 314 return (t);
nsrwsurasak 0:7ef27b349b37 315 }