GPS GMS-6 Module

Dependents:   RwSDCard_Xml_GPS

Committer:
Lucyjungz
Date:
Sun May 15 10:10:53 2016 +0000
Revision:
2:3064a132bc39
Parent:
1:dceb4eaf697e
Child:
3:910f54a89372
Rename function with proper prefix

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 1:dceb4eaf697e 67 else if (buf[buf_index] == ',')
Lucyjungz 1:dceb4eaf697e 68 {
Lucyjungz 1:dceb4eaf697e 69 /* Empty Data */
nsrwsurasak 0:7ef27b349b37 70 status = GPS_Status_Empty;
nsrwsurasak 0:7ef27b349b37 71 memset(ret_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 1:dceb4eaf697e 110 if (buf[index] == '$')
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 */
nsrwsurasak 0:7ef27b349b37 127 if (buf[index] == 'G' &&
nsrwsurasak 0:7ef27b349b37 128 buf[index+1] == 'P' &&
nsrwsurasak 0:7ef27b349b37 129 buf[index+2] == 'R' &&
nsrwsurasak 0:7ef27b349b37 130 buf[index+3] == 'M' &&
nsrwsurasak 0:7ef27b349b37 131 buf[index+4] == 'C'
Lucyjungz 1:dceb4eaf697e 132 )
Lucyjungz 1:dceb4eaf697e 133 {
Lucyjungz 1:dceb4eaf697e 134
Lucyjungz 1:dceb4eaf697e 135 /* Populate the header to the variable */
nsrwsurasak 0:7ef27b349b37 136 unsigned int h_index;
nsrwsurasak 0:7ef27b349b37 137 for(h_index = 0; h_index < HEADER_SIZE; h_index++) {
nsrwsurasak 0:7ef27b349b37 138 m_gprmc.header[h_index] = buf[index + h_index];
nsrwsurasak 0:7ef27b349b37 139 }
Lucyjungz 1:dceb4eaf697e 140
Lucyjungz 1:dceb4eaf697e 141 /* Move to the next section */
nsrwsurasak 0:7ef27b349b37 142 index += HEADER_SIZE;
nsrwsurasak 0:7ef27b349b37 143 state = GPS_Process_Time;
nsrwsurasak 0:7ef27b349b37 144 }
Lucyjungz 1:dceb4eaf697e 145 }
Lucyjungz 1:dceb4eaf697e 146 else
Lucyjungz 1:dceb4eaf697e 147 {
nsrwsurasak 0:7ef27b349b37 148 break;
nsrwsurasak 0:7ef27b349b37 149 }
nsrwsurasak 0:7ef27b349b37 150
Lucyjungz 1:dceb4eaf697e 151 }
Lucyjungz 1:dceb4eaf697e 152 else
Lucyjungz 1:dceb4eaf697e 153 {
Lucyjungz 1:dceb4eaf697e 154 /* Process GRPMC section */
Lucyjungz 2:3064a132bc39 155 status = GPSGms6_ProcessGprmcSection(state, buf ,index, size, GET_GPRMC_SECTION_SIZE(state), GET_GPRMC_VARIABLE_ADDR(state));
Lucyjungz 1:dceb4eaf697e 156
Lucyjungz 1:dceb4eaf697e 157 /* Move to the next section */
nsrwsurasak 0:7ef27b349b37 158 adv_index = GET_GPRMC_SECTION_SIZE(state);
nsrwsurasak 0:7ef27b349b37 159 state = GET_GPRMC_NEXT_STATE(state) ;
nsrwsurasak 0:7ef27b349b37 160 }
nsrwsurasak 0:7ef27b349b37 161
nsrwsurasak 0:7ef27b349b37 162
Lucyjungz 1:dceb4eaf697e 163 if (status == GPS_Status_NotEnough || state == GPS_Process_Complete)
Lucyjungz 1:dceb4eaf697e 164 {
Lucyjungz 1:dceb4eaf697e 165 /* In case of status not normal, then done */
nsrwsurasak 0:7ef27b349b37 166 break;
Lucyjungz 1:dceb4eaf697e 167 }
Lucyjungz 1:dceb4eaf697e 168 else if (status == GPS_Status_Valid)
Lucyjungz 1:dceb4eaf697e 169 {
Lucyjungz 1:dceb4eaf697e 170 /* Status is valid, move on */
nsrwsurasak 0:7ef27b349b37 171 index += adv_index;
nsrwsurasak 0:7ef27b349b37 172 }
nsrwsurasak 0:7ef27b349b37 173 }
nsrwsurasak 0:7ef27b349b37 174
Lucyjungz 1:dceb4eaf697e 175 /* Check validity of the data */
nsrwsurasak 0:7ef27b349b37 176 if (m_gprmc.indicator[0] == (char)'A' &&
nsrwsurasak 0:7ef27b349b37 177 m_gprmc.indicator[0] == (char)'D' &&
nsrwsurasak 0:7ef27b349b37 178 m_gprmc.indicator[0] == (char)'E'
Lucyjungz 1:dceb4eaf697e 179 )
Lucyjungz 1:dceb4eaf697e 180 {
Lucyjungz 1:dceb4eaf697e 181 /* If valid, populate to the valid variable */
nsrwsurasak 0:7ef27b349b37 182 m_available= true;
nsrwsurasak 0:7ef27b349b37 183 memcpy(&m_valid_gprmc, &m_gprmc , sizeof(m_gprmc));
nsrwsurasak 0:7ef27b349b37 184 }
nsrwsurasak 0:7ef27b349b37 185 }
nsrwsurasak 0:7ef27b349b37 186
Lucyjungz 1:dceb4eaf697e 187 /**
Lucyjungz 1:dceb4eaf697e 188 * @brief Callback function that process when the message is completed
Lucyjungz 1:dceb4eaf697e 189 * @note Rx Serial Interrupt must be properly started
Lucyjungz 1:dceb4eaf697e 190 * @retval
Lucyjungz 1:dceb4eaf697e 191 */
nsrwsurasak 0:7ef27b349b37 192 void complete_callback()
nsrwsurasak 0:7ef27b349b37 193 {
Lucyjungz 1:dceb4eaf697e 194 /* Process GPS Data once message is completed read */
Lucyjungz 2:3064a132bc39 195 GPSGms6_ProcessGpsData(m_RxBuf, RX_BUF_SIZE);
nsrwsurasak 0:7ef27b349b37 196 }
Lucyjungz 1:dceb4eaf697e 197 /**
Lucyjungz 1:dceb4eaf697e 198 * @brief Callback function that process when a charector is transfered
Lucyjungz 1:dceb4eaf697e 199 * @note Rx Serial Interrupt must be properly started
Lucyjungz 1:dceb4eaf697e 200 * @retval
Lucyjungz 1:dceb4eaf697e 201 */
nsrwsurasak 0:7ef27b349b37 202 void byte_callback()
nsrwsurasak 0:7ef27b349b37 203 {
Lucyjungz 1:dceb4eaf697e 204 /* Note: you need to actually read from the serial to clear the RX interrupt */
nsrwsurasak 0:7ef27b349b37 205 m_RxBuf[m_index] = serial_gps.getc();
nsrwsurasak 0:7ef27b349b37 206 m_index++;
Lucyjungz 1:dceb4eaf697e 207 if (m_index == RX_BUF_SIZE)
Lucyjungz 1:dceb4eaf697e 208 {
Lucyjungz 1:dceb4eaf697e 209 /* Buffer is full, call complete callback */
nsrwsurasak 0:7ef27b349b37 210 m_index = 0;
nsrwsurasak 0:7ef27b349b37 211 complete_callback();
nsrwsurasak 0:7ef27b349b37 212 }
nsrwsurasak 0:7ef27b349b37 213 }
Lucyjungz 1:dceb4eaf697e 214
Lucyjungz 1:dceb4eaf697e 215
Lucyjungz 1:dceb4eaf697e 216 /**
Lucyjungz 1:dceb4eaf697e 217 * @brief Constructor for GPS module
Lucyjungz 1:dceb4eaf697e 218 * @note
Lucyjungz 1:dceb4eaf697e 219 * @retval
Lucyjungz 1:dceb4eaf697e 220 */
nsrwsurasak 0:7ef27b349b37 221 GPSGms6::GPSGms6()
nsrwsurasak 0:7ef27b349b37 222 {
nsrwsurasak 0:7ef27b349b37 223
nsrwsurasak 0:7ef27b349b37 224 m_index = 0;
nsrwsurasak 0:7ef27b349b37 225 m_available = false;
nsrwsurasak 0:7ef27b349b37 226
Lucyjungz 1:dceb4eaf697e 227 /* Talking on 9600 bps */
nsrwsurasak 0:7ef27b349b37 228 serial_gps.baud(9600);
nsrwsurasak 0:7ef27b349b37 229
nsrwsurasak 0:7ef27b349b37 230 }
Lucyjungz 1:dceb4eaf697e 231
Lucyjungz 1:dceb4eaf697e 232 /**
Lucyjungz 1:dceb4eaf697e 233 * @brief Function to start GPS Module
Lucyjungz 1:dceb4eaf697e 234 * @note after started, interrupt will always be active
Lucyjungz 1:dceb4eaf697e 235 * @retval
Lucyjungz 1:dceb4eaf697e 236 */
nsrwsurasak 0:7ef27b349b37 237 void GPSGms6::start_GPS()
nsrwsurasak 0:7ef27b349b37 238 {
Lucyjungz 1:dceb4eaf697e 239 /* Start Rx interrupt */
nsrwsurasak 0:7ef27b349b37 240 serial_gps.attach(&byte_callback);
nsrwsurasak 0:7ef27b349b37 241 }
Lucyjungz 1:dceb4eaf697e 242
Lucyjungz 1:dceb4eaf697e 243 /**
Lucyjungz 1:dceb4eaf697e 244 * @brief Function to get latest GPRMC data
Lucyjungz 1:dceb4eaf697e 245 * @note
Lucyjungz 1:dceb4eaf697e 246 * @retval latest GPRMC data
Lucyjungz 1:dceb4eaf697e 247 */
nsrwsurasak 0:7ef27b349b37 248 GPRMC_Data_TypeDef GPSGms6::latestGPRMC()
nsrwsurasak 0:7ef27b349b37 249 {
nsrwsurasak 0:7ef27b349b37 250 return (m_gprmc);
nsrwsurasak 0:7ef27b349b37 251 }
Lucyjungz 1:dceb4eaf697e 252 /**
Lucyjungz 1:dceb4eaf697e 253 * @brief Function to get latest and valid GPRMC
Lucyjungz 1:dceb4eaf697e 254 * @note
Lucyjungz 1:dceb4eaf697e 255 * @retval valid GPRMC data
Lucyjungz 1:dceb4eaf697e 256 */
nsrwsurasak 0:7ef27b349b37 257 GPRMC_Data_TypeDef GPSGms6::validGPRMC()
nsrwsurasak 0:7ef27b349b37 258 {
nsrwsurasak 0:7ef27b349b37 259 m_available = false;
nsrwsurasak 0:7ef27b349b37 260 return (m_valid_gprmc);
nsrwsurasak 0:7ef27b349b37 261 }
Lucyjungz 1:dceb4eaf697e 262
Lucyjungz 1:dceb4eaf697e 263 /**
Lucyjungz 1:dceb4eaf697e 264 * @brief Function to get available flag of the valid GPRMC data
Lucyjungz 1:dceb4eaf697e 265 * @note
Lucyjungz 1:dceb4eaf697e 266 * @retval latest GPRMC data
Lucyjungz 1:dceb4eaf697e 267 */
nsrwsurasak 0:7ef27b349b37 268 bool GPSGms6::available()
nsrwsurasak 0:7ef27b349b37 269 {
nsrwsurasak 0:7ef27b349b37 270 return (m_available);
nsrwsurasak 0:7ef27b349b37 271 }
Lucyjungz 1:dceb4eaf697e 272 /**
Lucyjungz 1:dceb4eaf697e 273 * @brief Function to get UTC time
Lucyjungz 1:dceb4eaf697e 274 * @note
Lucyjungz 1:dceb4eaf697e 275 * @retval UTC time tn fm struct format
Lucyjungz 1:dceb4eaf697e 276 */
nsrwsurasak 0:7ef27b349b37 277 tm GPSGms6::UTCTime()
nsrwsurasak 0:7ef27b349b37 278 {
nsrwsurasak 0:7ef27b349b37 279 struct tm t;
Lucyjungz 1:dceb4eaf697e 280
Lucyjungz 1:dceb4eaf697e 281 /* Check available of date and time */
nsrwsurasak 0:7ef27b349b37 282 if (m_gprmc.date[0] != ' ' && m_gprmc.time[0] != ' ' )
nsrwsurasak 0:7ef27b349b37 283 {
Lucyjungz 1:dceb4eaf697e 284
Lucyjungz 1:dceb4eaf697e 285 /* Allocate buffer for buffering */
nsrwsurasak 0:7ef27b349b37 286 char str[3];
nsrwsurasak 0:7ef27b349b37 287
Lucyjungz 1:dceb4eaf697e 288 /* populate the second */
nsrwsurasak 0:7ef27b349b37 289 memcpy( str, &m_gprmc.time[4], 2 );
nsrwsurasak 0:7ef27b349b37 290 t.tm_sec = atoi(str);
Lucyjungz 1:dceb4eaf697e 291
Lucyjungz 1:dceb4eaf697e 292 /* populate the minute */
nsrwsurasak 0:7ef27b349b37 293 memcpy( str, &m_gprmc.time[2], 2 );
nsrwsurasak 0:7ef27b349b37 294 t.tm_min = atoi(str);
Lucyjungz 1:dceb4eaf697e 295
Lucyjungz 1:dceb4eaf697e 296 /* populate the hour */
nsrwsurasak 0:7ef27b349b37 297 memcpy( str, &m_gprmc.time[0], 2 );
nsrwsurasak 0:7ef27b349b37 298 t.tm_hour = atoi(str);
nsrwsurasak 0:7ef27b349b37 299
Lucyjungz 1:dceb4eaf697e 300 /* populate the date */
nsrwsurasak 0:7ef27b349b37 301 memcpy( str, &m_gprmc.date[0], 2 );
nsrwsurasak 0:7ef27b349b37 302 t.tm_mday = atoi(str);
nsrwsurasak 0:7ef27b349b37 303
Lucyjungz 1:dceb4eaf697e 304 /* populate the month */
nsrwsurasak 0:7ef27b349b37 305 memcpy( str, &m_gprmc.date[2], 2 );
nsrwsurasak 0:7ef27b349b37 306 t.tm_mon = atoi(str);
nsrwsurasak 0:7ef27b349b37 307
Lucyjungz 1:dceb4eaf697e 308 /* populate the year */
nsrwsurasak 0:7ef27b349b37 309 memcpy( str, &m_gprmc.date[4], 2 );
nsrwsurasak 0:7ef27b349b37 310 t.tm_year = atoi(str);
nsrwsurasak 0:7ef27b349b37 311 }
nsrwsurasak 0:7ef27b349b37 312 else
nsrwsurasak 0:7ef27b349b37 313 {
Lucyjungz 1:dceb4eaf697e 314 /* Found nothing */
nsrwsurasak 0:7ef27b349b37 315 t.tm_mday = 0;
nsrwsurasak 0:7ef27b349b37 316 t.tm_mon = 0;
nsrwsurasak 0:7ef27b349b37 317 t.tm_year = 0;
nsrwsurasak 0:7ef27b349b37 318 }
Lucyjungz 1:dceb4eaf697e 319
Lucyjungz 1:dceb4eaf697e 320 /* Return the time !! */
nsrwsurasak 0:7ef27b349b37 321 return (t);
nsrwsurasak 0:7ef27b349b37 322 }