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