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