GPS GMS-6 Module
GPSGms6.h@5:9dd9ab613497, 2016-05-18 (annotated)
- Committer:
- Lucyjungz
- Date:
- Wed May 18 17:28:10 2016 +0000
- Revision:
- 5:9dd9ab613497
- Parent:
- 4:fb1cd9893eb8
- Child:
- 6:5e30784ffd54
Add more comments and constant
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 | 4:fb1cd9893eb8 | 44 | #define IS_INDICATOR_VALID(indicator) ((indicator == (char)'A') || (indicator == (char)'D')|| (indicator == (char)'E')) |
Lucyjungz | 4:fb1cd9893eb8 | 45 | #define IS_HEADER_GPRPC(buf) buf[index] == 'G' && \ |
Lucyjungz | 4:fb1cd9893eb8 | 46 | buf[index+1] == 'P' && \ |
Lucyjungz | 4:fb1cd9893eb8 | 47 | buf[index+2] == 'R' && \ |
Lucyjungz | 4:fb1cd9893eb8 | 48 | buf[index+3] == 'M' && \ |
Lucyjungz | 4:fb1cd9893eb8 | 49 | buf[index+4] == 'C' |
Lucyjungz | 4:fb1cd9893eb8 | 50 | |
nsrwsurasak | 0:7ef27b349b37 | 51 | |
Lucyjungz | 1:dceb4eaf697e | 52 | /* ############### Enum ################## */ |
nsrwsurasak | 0:7ef27b349b37 | 53 | typedef enum GPS_ProcessState { |
Lucyjungz | 4:fb1cd9893eb8 | 54 | GPS_Process_Start = 0, /** State Start processing */ |
Lucyjungz | 4:fb1cd9893eb8 | 55 | GPS_Process_Header, /** State process header */ |
Lucyjungz | 4:fb1cd9893eb8 | 56 | GPS_Process_Time, /** State process Time */ |
Lucyjungz | 4:fb1cd9893eb8 | 57 | GPS_Process_Status, /** State process status */ |
Lucyjungz | 4:fb1cd9893eb8 | 58 | GPS_Process_Latitude, /** State process Latitude */ |
Lucyjungz | 4:fb1cd9893eb8 | 59 | GPS_Process_Latitude_hemis, /** State process Latitude hemis */ |
Lucyjungz | 4:fb1cd9893eb8 | 60 | GPS_Process_Longitude, /** State process Longitude */ |
Lucyjungz | 4:fb1cd9893eb8 | 61 | GPS_Process_Longitude_hemis, /** State process Longitude hemis */ |
Lucyjungz | 4:fb1cd9893eb8 | 62 | GPS_Process_Speed, /** State process Speed */ |
Lucyjungz | 4:fb1cd9893eb8 | 63 | GPS_Process_Course, /** State process Course */ |
Lucyjungz | 4:fb1cd9893eb8 | 64 | GPS_Process_Date, /** State process Date */ |
Lucyjungz | 4:fb1cd9893eb8 | 65 | GPS_Process_Magnetic, /** State process Magnetic */ |
Lucyjungz | 4:fb1cd9893eb8 | 66 | GPS_Process_Magnetic_Dir, /** State process Magnetic Dir */ |
Lucyjungz | 4:fb1cd9893eb8 | 67 | GPS_Process_Indicator, /** State process Indicator */ |
Lucyjungz | 4:fb1cd9893eb8 | 68 | GPS_Process_Complete , /** State process Complete */ |
Lucyjungz | 4:fb1cd9893eb8 | 69 | GPS_Process_SIZE /** NUMBER OF STATEs */ |
nsrwsurasak | 0:7ef27b349b37 | 70 | } GPS_ProcessState; |
nsrwsurasak | 0:7ef27b349b37 | 71 | |
nsrwsurasak | 0:7ef27b349b37 | 72 | typedef enum GPS_ProcessStatus { |
Lucyjungz | 4:fb1cd9893eb8 | 73 | GPS_Status_Valid, /** Status valid */ |
Lucyjungz | 4:fb1cd9893eb8 | 74 | GPS_Status_Empty, /** Status data is empty */ |
Lucyjungz | 4:fb1cd9893eb8 | 75 | GPS_Status_NotEnough, /** Status Receive Buffer is not enough to process */ |
nsrwsurasak | 0:7ef27b349b37 | 76 | } GPS_ProcessStatus; |
nsrwsurasak | 0:7ef27b349b37 | 77 | |
Lucyjungz | 1:dceb4eaf697e | 78 | |
Lucyjungz | 1:dceb4eaf697e | 79 | /* ############### Structure ################## */ |
Lucyjungz | 1:dceb4eaf697e | 80 | typedef struct { |
Lucyjungz | 4:fb1cd9893eb8 | 81 | char header[HEADER_SIZE+1]; /** Specific section for header data */ |
Lucyjungz | 4:fb1cd9893eb8 | 82 | char time[GPRMC_TIME_SIZE+1]; /** Specific section for time data */ |
Lucyjungz | 4:fb1cd9893eb8 | 83 | char status[GPRMC_STATUS_SIZE+1]; /** Specific section for status data */ |
Lucyjungz | 4:fb1cd9893eb8 | 84 | char latitude[GPRMC_LATITUDE_SIZE+1]; /** Specific section for latitude data */ |
Lucyjungz | 4:fb1cd9893eb8 | 85 | char latitude_hemi[GPRMC_LATITUDE_HEMI_SIZE+1]; /** Specific section for latitude hemi data */ |
Lucyjungz | 4:fb1cd9893eb8 | 86 | char longitude[GPRMC_LONGITUDE_SIZE+1]; /** Specific section for longitude data */ |
Lucyjungz | 4:fb1cd9893eb8 | 87 | char longitude_hemi[GPRMC_LATITUDE_HEMI_SIZE+1]; /** Specific section for longitude hemi data */ |
Lucyjungz | 4:fb1cd9893eb8 | 88 | char speed[GPRMC_SPEED_SIZE+1]; /** Specific section for speed data */ |
Lucyjungz | 4:fb1cd9893eb8 | 89 | char course[GPRMC_COURSE_SIZE+1]; /** Specific section for Course data */ |
Lucyjungz | 4:fb1cd9893eb8 | 90 | char date[GPRMC_DATE_SIZE+1]; /** Specific section for Date data */ |
Lucyjungz | 4:fb1cd9893eb8 | 91 | char magnetic[GPRMC_MAGNETIC_SIZE+1]; /** Specific section for Magnetic data */ |
Lucyjungz | 4:fb1cd9893eb8 | 92 | char magnetic_dir[GPRMC_MAGNETIC_DIR_SIZE+1]; /** Specific section for Magnetic dir data */ |
Lucyjungz | 4:fb1cd9893eb8 | 93 | char indicator[GPRMC_INDICATOR_SIZE+1]; /** Specific section for Indicator data */ |
Lucyjungz | 1:dceb4eaf697e | 94 | } GPRMC_Data_TypeDef; |
Lucyjungz | 1:dceb4eaf697e | 95 | |
Lucyjungz | 1:dceb4eaf697e | 96 | |
nsrwsurasak | 0:7ef27b349b37 | 97 | typedef struct { |
Lucyjungz | 4:fb1cd9893eb8 | 98 | GPS_ProcessState state; /** indicate index of the table */ |
Lucyjungz | 4:fb1cd9893eb8 | 99 | int size; /** section size */ |
Lucyjungz | 4:fb1cd9893eb8 | 100 | char * p_val; /** pointer to variable to be store */ |
nsrwsurasak | 0:7ef27b349b37 | 101 | } GPRMC_Tbl_TypeDef; |
nsrwsurasak | 0:7ef27b349b37 | 102 | |
nsrwsurasak | 0:7ef27b349b37 | 103 | |
Lucyjungz | 1:dceb4eaf697e | 104 | /* ############### Class ################## */ |
nsrwsurasak | 0:7ef27b349b37 | 105 | class GPSGms6 |
nsrwsurasak | 0:7ef27b349b37 | 106 | { |
nsrwsurasak | 0:7ef27b349b37 | 107 | public: |
nsrwsurasak | 0:7ef27b349b37 | 108 | |
Lucyjungz | 1:dceb4eaf697e | 109 | /** |
Lucyjungz | 1:dceb4eaf697e | 110 | * Constructor |
Lucyjungz | 1:dceb4eaf697e | 111 | */ |
nsrwsurasak | 0:7ef27b349b37 | 112 | GPSGms6(); |
nsrwsurasak | 0:7ef27b349b37 | 113 | |
Lucyjungz | 1:dceb4eaf697e | 114 | /** |
Lucyjungz | 1:dceb4eaf697e | 115 | * Start GPS |
Lucyjungz | 1:dceb4eaf697e | 116 | */ |
nsrwsurasak | 0:7ef27b349b37 | 117 | void start_GPS(); |
Lucyjungz | 1:dceb4eaf697e | 118 | |
Lucyjungz | 1:dceb4eaf697e | 119 | /** |
Lucyjungz | 1:dceb4eaf697e | 120 | * Get UTC Time |
Lucyjungz | 1:dceb4eaf697e | 121 | * @returns |
Lucyjungz | 1:dceb4eaf697e | 122 | * UTC Time |
Lucyjungz | 1:dceb4eaf697e | 123 | */ |
nsrwsurasak | 0:7ef27b349b37 | 124 | tm UTCTime(); |
nsrwsurasak | 0:7ef27b349b37 | 125 | /** Get Latest GPRMC Data |
nsrwsurasak | 0:7ef27b349b37 | 126 | * |
nsrwsurasak | 0:7ef27b349b37 | 127 | * @returns |
nsrwsurasak | 0:7ef27b349b37 | 128 | * Latest GPRMC Data |
nsrwsurasak | 0:7ef27b349b37 | 129 | */ |
nsrwsurasak | 0:7ef27b349b37 | 130 | GPRMC_Data_TypeDef latestGPRMC(); |
nsrwsurasak | 0:7ef27b349b37 | 131 | |
nsrwsurasak | 0:7ef27b349b37 | 132 | /** Get Valid Data Interval |
nsrwsurasak | 0:7ef27b349b37 | 133 | * |
nsrwsurasak | 0:7ef27b349b37 | 134 | * @returns |
nsrwsurasak | 0:7ef27b349b37 | 135 | * Valid Data Interval |
nsrwsurasak | 0:7ef27b349b37 | 136 | */ |
nsrwsurasak | 0:7ef27b349b37 | 137 | GPRMC_Data_TypeDef validGPRMC(); |
nsrwsurasak | 0:7ef27b349b37 | 138 | |
nsrwsurasak | 0:7ef27b349b37 | 139 | /** Get availability of gprmc |
nsrwsurasak | 0:7ef27b349b37 | 140 | * |
nsrwsurasak | 0:7ef27b349b37 | 141 | * @returns |
nsrwsurasak | 0:7ef27b349b37 | 142 | * 'true' - if data is available |
nsrwsurasak | 0:7ef27b349b37 | 143 | */ |
nsrwsurasak | 0:7ef27b349b37 | 144 | bool available(); |
nsrwsurasak | 0:7ef27b349b37 | 145 | |
nsrwsurasak | 0:7ef27b349b37 | 146 | |
nsrwsurasak | 0:7ef27b349b37 | 147 | private: |
nsrwsurasak | 0:7ef27b349b37 | 148 | |
nsrwsurasak | 0:7ef27b349b37 | 149 | }; |