Csr location class shows location and satellite information, which supports H13467 + ST F103RB/NXP LCP1549 boards now.

Dependents:   CsrLocationDemo CsrLocationDemo

Fork of CsrLocation by jie zhao

Committer:
zhjcpi
Date:
Tue Mar 25 05:26:26 2014 +0000
Revision:
1:bbaf9b8d646a
Parent:
0:aba381fc8158
Child:
2:d4fe184925f2
optimization csrLocation class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zhjcpi 0:aba381fc8158 1
zhjcpi 0:aba381fc8158 2 /* CsrLocation class for mbed Microcontroller
zhjcpi 0:aba381fc8158 3 * Copyright 2014 CSR plc
zhjcpi 0:aba381fc8158 4 */
zhjcpi 0:aba381fc8158 5
zhjcpi 0:aba381fc8158 6
zhjcpi 0:aba381fc8158 7 #ifndef CSRLOCATION_H
zhjcpi 0:aba381fc8158 8 #define CSRLOCATION_H
zhjcpi 0:aba381fc8158 9
zhjcpi 0:aba381fc8158 10
zhjcpi 0:aba381fc8158 11 #define CSR_LOC_SDK_VER "CSR-LOC-SDK-0.5"
zhjcpi 0:aba381fc8158 12
zhjcpi 0:aba381fc8158 13 /* Data type definitions */
zhjcpi 0:aba381fc8158 14 #undef FALSE
zhjcpi 0:aba381fc8158 15 #define FALSE (0)
zhjcpi 0:aba381fc8158 16
zhjcpi 0:aba381fc8158 17 #undef TRUE
zhjcpi 0:aba381fc8158 18 #define TRUE (1)
zhjcpi 0:aba381fc8158 19
zhjcpi 0:aba381fc8158 20 /* Unsigned fixed width types */
zhjcpi 0:aba381fc8158 21 typedef unsigned char CsrUint8;
zhjcpi 0:aba381fc8158 22 typedef unsigned short CsrUint16;
zhjcpi 0:aba381fc8158 23 typedef unsigned int CsrUint32;
zhjcpi 0:aba381fc8158 24
zhjcpi 0:aba381fc8158 25 /* Signed fixed width types */
zhjcpi 0:aba381fc8158 26 typedef signed char CsrInt8;
zhjcpi 0:aba381fc8158 27 typedef signed short CsrInt16;
zhjcpi 0:aba381fc8158 28 typedef signed int CsrInt32;
zhjcpi 0:aba381fc8158 29
zhjcpi 0:aba381fc8158 30 /* Boolean */
zhjcpi 0:aba381fc8158 31 typedef CsrUint8 CsrBool;
zhjcpi 0:aba381fc8158 32
zhjcpi 0:aba381fc8158 33 /* String types */
zhjcpi 0:aba381fc8158 34 typedef char CsrCharString;
zhjcpi 0:aba381fc8158 35 typedef CsrUint8 CsrUtf8String;
zhjcpi 0:aba381fc8158 36 typedef CsrUint16 CsrUtf16String; /* 16-bit UTF16 strings */
zhjcpi 0:aba381fc8158 37 typedef CsrUint32 CsrUint24;
zhjcpi 0:aba381fc8158 38
zhjcpi 0:aba381fc8158 39 /*
zhjcpi 0:aba381fc8158 40 * Floating point
zhjcpi 0:aba381fc8158 41 *
zhjcpi 0:aba381fc8158 42 * Note: If a given compiler does not support floating point, it is
zhjcpi 0:aba381fc8158 43 * OK to omit these definitions; alternative versions of the code using
zhjcpi 0:aba381fc8158 44 * these types may be available. Consult the relevant documentation
zhjcpi 0:aba381fc8158 45 * or the customer support group for information on this.
zhjcpi 0:aba381fc8158 46 */
zhjcpi 0:aba381fc8158 47 typedef float CsrFloat;
zhjcpi 0:aba381fc8158 48 typedef double CsrDouble;
zhjcpi 0:aba381fc8158 49
zhjcpi 0:aba381fc8158 50 typedef CsrUint16 CsrResult;
zhjcpi 0:aba381fc8158 51 #define CSR_RESULT_SUCCESS ((CsrResult) 0x0000)
zhjcpi 0:aba381fc8158 52 #define CSR_RESULT_FAILURE ((CsrResult) 0xFFFF)
zhjcpi 0:aba381fc8158 53 /* The end of data type definitions */
zhjcpi 0:aba381fc8158 54
zhjcpi 0:aba381fc8158 55 /* OSP protocol related definitions */
zhjcpi 0:aba381fc8158 56 #define MAX_VERSION_LENGTH 80
zhjcpi 0:aba381fc8158 57
zhjcpi 0:aba381fc8158 58 /* OSP message header */
zhjcpi 0:aba381fc8158 59 #define OSP_MSG_HEAD0 (0xA0)
zhjcpi 0:aba381fc8158 60 #define OSP_MSG_HEAD1 (0xA2)
zhjcpi 0:aba381fc8158 61 /* OSP message footer */
zhjcpi 0:aba381fc8158 62 #define OSP_MSG_TAIL0 (0xB0)
zhjcpi 0:aba381fc8158 63 #define OSP_MSG_TAIL1 (0xB3)
zhjcpi 0:aba381fc8158 64
zhjcpi 0:aba381fc8158 65 /* NMEA message header */
zhjcpi 0:aba381fc8158 66 #define NMEA_MSG_HEAD0 ('$')
zhjcpi 0:aba381fc8158 67 #define NMEA_MSG_HEAD1 ('G')
zhjcpi 0:aba381fc8158 68 /* NMEA message footer */
zhjcpi 0:aba381fc8158 69 #define NMEA_MSG_TAIL0 ('*')
zhjcpi 0:aba381fc8158 70
zhjcpi 0:aba381fc8158 71 #define CSR_SWAPIN16(bytestream) (((CsrUint16)*((bytestream)+0) << 8) | ((CsrUint16)*((bytestream)+1)))
zhjcpi 0:aba381fc8158 72
zhjcpi 0:aba381fc8158 73 #define CSR_SWAPIN32(bytestream)\
zhjcpi 0:aba381fc8158 74 ( ((CsrUint32)*((bytestream)+0) << 24)\
zhjcpi 0:aba381fc8158 75 | ((CsrUint32)*((bytestream)+1) << 16)\
zhjcpi 0:aba381fc8158 76 | ((CsrUint32)*((bytestream)+2) << 8)\
zhjcpi 0:aba381fc8158 77 | ((CsrUint32)*((bytestream)+3) ))
zhjcpi 0:aba381fc8158 78
zhjcpi 0:aba381fc8158 79
zhjcpi 0:aba381fc8158 80 /* import macros for little endian: */
zhjcpi 0:aba381fc8158 81 /* NOTE: must use {} around these macros when calling in a loop */
zhjcpi 0:aba381fc8158 82 #define BINARY_IMPORT_UINT8(bytestream) ( *((bytestream)++))
zhjcpi 0:aba381fc8158 83 #define BINARY_IMPORT_UINT16(bytestream) ((CsrUint16) CSR_SWAPIN16((bytestream))); bytestream+=2
zhjcpi 0:aba381fc8158 84 #define BINARY_IMPORT_UINT32(bytestream) ((CsrUint32) CSR_SWAPIN32((bytestream))); bytestream+=4
zhjcpi 0:aba381fc8158 85 #define BINARY_IMPORT_SINT32(bytestream) ((CsrInt32) CSR_SWAPIN32((bytestream))); bytestream+=4
zhjcpi 0:aba381fc8158 86
zhjcpi 0:aba381fc8158 87
zhjcpi 0:aba381fc8158 88 #define OSP_MAKE_MSG_ID(mid, sid) ((((mid) & 0xFF) << 8) | ((sid) & 0xFF))
zhjcpi 0:aba381fc8158 89
zhjcpi 0:aba381fc8158 90 #define OSP_MSG_SW_VERSION OSP_MAKE_MSG_ID(0x06, 0x0)
zhjcpi 0:aba381fc8158 91 #define OSP_MSG_OK_TO_SEND OSP_MAKE_MSG_ID(0x12, 0x0)
zhjcpi 0:aba381fc8158 92 #define OSP_MSG_GEODETIC_NAVIGATION OSP_MAKE_MSG_ID(0x29, 0x0)
zhjcpi 0:aba381fc8158 93 #define OSP_MSG_MULTI_CONSTELLATION OSP_MAKE_MSG_ID(0x43, 0x0)
zhjcpi 0:aba381fc8158 94 #define OSP_MSG_GNSS_NAV_DATA OSP_MAKE_MSG_ID(0x43, 0x01)
zhjcpi 0:aba381fc8158 95 #define OSP_MSG_GNSS_SAT_DATA OSP_MAKE_MSG_ID(0x43, 0x10)
zhjcpi 0:aba381fc8158 96 #define OSP_MSG_HW_CONFIG_REQ OSP_MAKE_MSG_ID(0x47, 0x0)
zhjcpi 0:aba381fc8158 97 #define OSP_MSG_PWR_MODE_RSP OSP_MAKE_MSG_ID(0x5A, 0x0)
zhjcpi 0:aba381fc8158 98 #define OSP_MSG_PWR_MODE_FPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x0)
zhjcpi 0:aba381fc8158 99 #define OSP_MSG_PWR_MODE_LPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x6)
zhjcpi 0:aba381fc8158 100
zhjcpi 0:aba381fc8158 101
zhjcpi 0:aba381fc8158 102 #define GNSS_SAT_DATA_NUM_OF_SATS (15)
zhjcpi 0:aba381fc8158 103 #define CODEC_GLO_MAX_CHANNELS (14)
zhjcpi 0:aba381fc8158 104 /* The end of OSP protocol definitions */
zhjcpi 0:aba381fc8158 105
zhjcpi 0:aba381fc8158 106
zhjcpi 0:aba381fc8158 107 #define LOC_MAX_GNSS_SVS (32)
zhjcpi 0:aba381fc8158 108 #define LOC_GLO_FREQ_OFFSET (77)
zhjcpi 0:aba381fc8158 109 #define LOC_GLO_FREQ_ID_START (70)
zhjcpi 0:aba381fc8158 110 #define LOC_GLO_FREQ_ID_END (83)
zhjcpi 0:aba381fc8158 111 #define LOC_NUM_OF_GLO_FREQ_CHANNELS (1+LOC_GLO_FREQ_ID_END-LOC_GLO_FREQ_ID_START)
zhjcpi 0:aba381fc8158 112
zhjcpi 0:aba381fc8158 113 #define MAX_PORT_NUM_STRING_LENGTH (16)
zhjcpi 0:aba381fc8158 114 #define MAX_SERIAL_BUF_LEN (2048)
zhjcpi 0:aba381fc8158 115 #define MAX_SERIAL_PKT_LEN (512)
zhjcpi 0:aba381fc8158 116
zhjcpi 0:aba381fc8158 117 #define BAUDRATE_NMEA 4800
zhjcpi 0:aba381fc8158 118 #define BAUDRATE_OSP 115200
zhjcpi 0:aba381fc8158 119
zhjcpi 0:aba381fc8158 120 #define PROTO_CHECK_TIMEOUT (2.0)
zhjcpi 0:aba381fc8158 121
zhjcpi 0:aba381fc8158 122 /** Indicates the outputted location information */
zhjcpi 0:aba381fc8158 123 #define LOC_OUTPUT_LOCATION (1)
zhjcpi 0:aba381fc8158 124 /* Indicates the outputted sv status information */
zhjcpi 0:aba381fc8158 125 #define LOC_OUTPUT_SV_STATUS (2)
zhjcpi 0:aba381fc8158 126
zhjcpi 0:aba381fc8158 127 #define CSR_LOG_INFO(...) \
zhjcpi 0:aba381fc8158 128 {\
zhjcpi 0:aba381fc8158 129 if(csrLocInst.pSerialDebug != NULL)\
zhjcpi 0:aba381fc8158 130 {\
zhjcpi 0:aba381fc8158 131 (csrLocInst.pSerialDebug->printf(__VA_ARGS__));\
zhjcpi 0:aba381fc8158 132 }\
zhjcpi 0:aba381fc8158 133 }
zhjcpi 0:aba381fc8158 134
zhjcpi 0:aba381fc8158 135 /** Location enent definitions */
zhjcpi 0:aba381fc8158 136 typedef enum
zhjcpi 0:aba381fc8158 137 {
zhjcpi 0:aba381fc8158 138 /** Start result event */
zhjcpi 0:aba381fc8158 139 CSR_LOC_EVENT_START_RESULT,
zhjcpi 0:aba381fc8158 140 /** Stop result event */
zhjcpi 0:aba381fc8158 141 CSR_LOC_EVENT_STOP_RESULT,
zhjcpi 0:aba381fc8158 142 }eCsrLocEventType;
zhjcpi 0:aba381fc8158 143
zhjcpi 0:aba381fc8158 144 /** Power mode selection */
zhjcpi 0:aba381fc8158 145 typedef enum
zhjcpi 0:aba381fc8158 146 {
zhjcpi 0:aba381fc8158 147 /** full power mode */
zhjcpi 0:aba381fc8158 148 PWR_FULL,
zhjcpi 0:aba381fc8158 149 /** Low power push to fix mode */
zhjcpi 0:aba381fc8158 150 PWR_PTF,
zhjcpi 0:aba381fc8158 151 }ePowerMode;
zhjcpi 0:aba381fc8158 152
zhjcpi 0:aba381fc8158 153 /* Protocol detection state */
zhjcpi 0:aba381fc8158 154 typedef enum
zhjcpi 0:aba381fc8158 155 {
zhjcpi 0:aba381fc8158 156 STATE_START1, /* Indicates the first byte of the OSP or NMEA message header*/
zhjcpi 0:aba381fc8158 157 STATE_START2, /* Indicates the second byte of the OSP or NMEA message header */
zhjcpi 0:aba381fc8158 158 STATE_SIZE1, /* Indicates the first byte of the OSP message length */
zhjcpi 0:aba381fc8158 159 STATE_SIZE2, /* Indicates the second byte of the OSP message length */
zhjcpi 0:aba381fc8158 160 STATE_PAYLOAD, /* Indicates the start of payload of the OSP message */
zhjcpi 0:aba381fc8158 161 STATE_CHECKSUM1, /* Indicates the first byte of the OSP message checksum */
zhjcpi 0:aba381fc8158 162 STATE_CHECKSUM2, /* Indicates the second byte of the OSP message checksum */
zhjcpi 0:aba381fc8158 163 STATE_END1, /* Indicates the first byte of the OSP or NMEA message footer */
zhjcpi 0:aba381fc8158 164 STATE_END2 /* Indicates the second byte of the OSP message footer */
zhjcpi 0:aba381fc8158 165 }eProtoDetState;
zhjcpi 0:aba381fc8158 166
zhjcpi 0:aba381fc8158 167 /* Csr Location state */
zhjcpi 0:aba381fc8158 168 typedef enum
zhjcpi 0:aba381fc8158 169 {
zhjcpi 0:aba381fc8158 170 CSR_LOC_STATE_IDLE,
zhjcpi 0:aba381fc8158 171 CSR_LOC_STATE_RUN,
zhjcpi 0:aba381fc8158 172 }eCsrLocState;
zhjcpi 0:aba381fc8158 173
zhjcpi 0:aba381fc8158 174 /* Locatin chip protocol detection state */
zhjcpi 0:aba381fc8158 175 typedef enum
zhjcpi 0:aba381fc8158 176 {
zhjcpi 0:aba381fc8158 177 PROTO_STATE_DET_INVALID = 0,
zhjcpi 0:aba381fc8158 178 PROTO_STATE_DET_OSP,
zhjcpi 0:aba381fc8158 179 PROTO_STATE_DET_NMEA,
zhjcpi 0:aba381fc8158 180 PROTO_STATE_SWI_OSP_FROM_NMEA,
zhjcpi 0:aba381fc8158 181 PROTO_STATE_DET_OSP_FROM_NMEA,
zhjcpi 0:aba381fc8158 182 PROTO_STATE_DET_OK,
zhjcpi 0:aba381fc8158 183 }eProtoState;
zhjcpi 0:aba381fc8158 184
zhjcpi 0:aba381fc8158 185 /* Locaiton chip status */
zhjcpi 0:aba381fc8158 186 typedef enum
zhjcpi 0:aba381fc8158 187 {
zhjcpi 0:aba381fc8158 188 /* Location chip is going to hibernation mode and cannot accept message any more */
zhjcpi 0:aba381fc8158 189 ENGINE_STATUS_NOTOK2SEND,
zhjcpi 0:aba381fc8158 190 /* Locaitn come back from hibernation mode and can accept message now */
zhjcpi 0:aba381fc8158 191 ENGINE_STATUS_OK2SEND
zhjcpi 0:aba381fc8158 192 }eEngineStatus;
zhjcpi 0:aba381fc8158 193
zhjcpi 0:aba381fc8158 194 /* OSP data type to be sent to location chip */
zhjcpi 0:aba381fc8158 195 typedef enum
zhjcpi 0:aba381fc8158 196 {
zhjcpi 0:aba381fc8158 197 SEND_DATA_TYPE_OSP_STOP_REQ,
zhjcpi 0:aba381fc8158 198 SEND_DATA_TYPE_OSP_VER_REQ,
zhjcpi 0:aba381fc8158 199 SEND_DATA_TYPE_OSP_LPM_REQ,
zhjcpi 0:aba381fc8158 200 SEND_DATA_TYPE_OSP_FPM_REQ,
zhjcpi 0:aba381fc8158 201 SEND_DATA_TYPE_OSP_SWITCH2NMEA_REQ,
zhjcpi 0:aba381fc8158 202 SEND_DATA_TYPE_NMEA_SWITCH2OSP_REQ
zhjcpi 0:aba381fc8158 203 }eSendDataType;
zhjcpi 0:aba381fc8158 204
zhjcpi 0:aba381fc8158 205 /** Structure to hold Position Response Message Information. */
zhjcpi 0:aba381fc8158 206 typedef struct LocPosResp
zhjcpi 0:aba381fc8158 207 {
zhjcpi 0:aba381fc8158 208 /** Week part of GPS time */
zhjcpi 0:aba381fc8158 209 CsrUint16 gps_week;
zhjcpi 0:aba381fc8158 210 /** Time of second part of GPS time */
zhjcpi 0:aba381fc8158 211 CsrUint32 tow;
zhjcpi 0:aba381fc8158 212 /** Latitude */
zhjcpi 0:aba381fc8158 213 CsrDouble lat;
zhjcpi 0:aba381fc8158 214 /** Longitude */
zhjcpi 0:aba381fc8158 215 CsrDouble lon;
zhjcpi 0:aba381fc8158 216 /** Altitude */
zhjcpi 0:aba381fc8158 217 CsrDouble alt;
zhjcpi 0:aba381fc8158 218 } tLocPosResp;
zhjcpi 0:aba381fc8158 219
zhjcpi 0:aba381fc8158 220 /** Structure to hold Satellite Information. */
zhjcpi 0:aba381fc8158 221 typedef struct LocSvInfo
zhjcpi 0:aba381fc8158 222 {
zhjcpi 0:aba381fc8158 223 /** Prn or svId */
zhjcpi 0:aba381fc8158 224 CsrUint8 prn;
zhjcpi 0:aba381fc8158 225 /** The ratio of carrier and noise */
zhjcpi 0:aba381fc8158 226 CsrFloat cno;
zhjcpi 0:aba381fc8158 227 /** elevation */
zhjcpi 0:aba381fc8158 228 CsrFloat elevation;
zhjcpi 0:aba381fc8158 229 /** azimuth */
zhjcpi 0:aba381fc8158 230 CsrFloat azimuth;
zhjcpi 0:aba381fc8158 231 /** satellite state */
zhjcpi 0:aba381fc8158 232 CsrUint16 state;
zhjcpi 0:aba381fc8158 233 } tLocSvInfo;
zhjcpi 0:aba381fc8158 234
zhjcpi 0:aba381fc8158 235 /** Structure to hold Satellite Information for GLONASS */
zhjcpi 0:aba381fc8158 236 typedef struct LocGloSvInfo
zhjcpi 0:aba381fc8158 237 {
zhjcpi 0:aba381fc8158 238 /** Prn or svId */
zhjcpi 0:aba381fc8158 239 CsrUint8 prn;
zhjcpi 0:aba381fc8158 240 /** Slot number */
zhjcpi 0:aba381fc8158 241 CsrUint8 sno;
zhjcpi 0:aba381fc8158 242 /** The ratio of carrier and noise */
zhjcpi 0:aba381fc8158 243 CsrFloat cno;
zhjcpi 0:aba381fc8158 244 /** elevation */
zhjcpi 0:aba381fc8158 245 CsrFloat elevation;
zhjcpi 0:aba381fc8158 246 /** azimuth */
zhjcpi 0:aba381fc8158 247 CsrFloat azimuth;
zhjcpi 0:aba381fc8158 248 /** satellite state */
zhjcpi 0:aba381fc8158 249 CsrUint16 state;
zhjcpi 0:aba381fc8158 250 } tLocGloSvInfo;
zhjcpi 0:aba381fc8158 251
zhjcpi 0:aba381fc8158 252 /** Structure to hold Satellite Status Information. */
zhjcpi 0:aba381fc8158 253 typedef struct LocSvStatus
zhjcpi 0:aba381fc8158 254 {
zhjcpi 0:aba381fc8158 255 /** Week part of GPS time */
zhjcpi 0:aba381fc8158 256 CsrUint16 gps_week;
zhjcpi 0:aba381fc8158 257 /** Time of second part of GPS time */
zhjcpi 0:aba381fc8158 258 CsrUint32 tow;
zhjcpi 0:aba381fc8158 259 /** Time of millisecond part of GPS time */
zhjcpi 0:aba381fc8158 260 CsrUint32 tow_sub_ms;
zhjcpi 0:aba381fc8158 261
zhjcpi 0:aba381fc8158 262 /**Number of GPS SVs currently visible **/
zhjcpi 0:aba381fc8158 263 CsrUint8 numOfSVs;
zhjcpi 0:aba381fc8158 264 /**Number of GLONASS SVs currently visible **/
zhjcpi 0:aba381fc8158 265 CsrUint8 numOfGloSVs;
zhjcpi 0:aba381fc8158 266 /** GPS SVs information */
zhjcpi 0:aba381fc8158 267 tLocSvInfo svList[LOC_MAX_GNSS_SVS];
zhjcpi 0:aba381fc8158 268 /** GLONASS SVs information */
zhjcpi 0:aba381fc8158 269 tLocGloSvInfo gloSvList[LOC_NUM_OF_GLO_FREQ_CHANNELS];
zhjcpi 0:aba381fc8158 270 /** Bit mask indicating which SVs have ephemeris data **/
zhjcpi 0:aba381fc8158 271 CsrUint32 ephemerisMask;
zhjcpi 0:aba381fc8158 272 /** Bit mask indicating which GLONASS SVs have ephemeris data **/
zhjcpi 0:aba381fc8158 273 CsrUint32 gloEphemerisMask;
zhjcpi 0:aba381fc8158 274 /** Bit mask indicating which SVs were used in latest sent fix **/
zhjcpi 0:aba381fc8158 275 CsrUint32 svUsedInFixMask;
zhjcpi 0:aba381fc8158 276 /** Bit mask indicating which GLONASS SVs were used in latest sent fix **/
zhjcpi 0:aba381fc8158 277 CsrUint32 gloSvUsedInFixMask;
zhjcpi 0:aba381fc8158 278 /** Bit mask indicating which QZSS SVs were used in latest sent fix **/
zhjcpi 0:aba381fc8158 279 CsrUint32 qzssSvUsedInFixMask;
zhjcpi 0:aba381fc8158 280 /** Bit mask indicating which SBAS SVs were used in latest sent fix **/
zhjcpi 0:aba381fc8158 281 CsrUint32 sbasSvUsedInFixMask;
zhjcpi 0:aba381fc8158 282 } tLocSvStatus;
zhjcpi 0:aba381fc8158 283
zhjcpi 0:aba381fc8158 284
zhjcpi 0:aba381fc8158 285 /** Applicaiton register this out callback function and CsrLocaiton class will pass outputted information to application */
zhjcpi 0:aba381fc8158 286 typedef void (*csr_app_output_callback)(CsrUint32 msgId, void * const pMsgData, CsrUint32 msgLength);
zhjcpi 0:aba381fc8158 287
zhjcpi 0:aba381fc8158 288 /** Applicaiton register this event callback function and CsrLocaiton class will pass internal porcessing event to application */
zhjcpi 0:aba381fc8158 289 typedef void (*csr_app_event_callback)(eCsrLocEventType event, CsrUint32 data);
zhjcpi 0:aba381fc8158 290
zhjcpi 0:aba381fc8158 291 /** tCsrLocConfig structure
zhjcpi 0:aba381fc8158 292 * Application needs to decides and pass the configuration into CsrLocation class.
zhjcpi 0:aba381fc8158 293 */
zhjcpi 0:aba381fc8158 294 typedef struct CsrLocConfig
zhjcpi 0:aba381fc8158 295 {
zhjcpi 0:aba381fc8158 296 /** Debug serial port to print debug information */
zhjcpi 0:aba381fc8158 297 Serial *pSerialDebug;
zhjcpi 0:aba381fc8158 298 /** location serail port to communicate between mbed host side and location chip */
zhjcpi 1:bbaf9b8d646a 299 RawSerial *pSerialLoc;
zhjcpi 0:aba381fc8158 300 /** GPIO pin to control location chip on, a rising edge is uset to activate location chip. Please note, before activate chip, reset pin should be pull high */
zhjcpi 0:aba381fc8158 301 DigitalOut *pPinOnoff;
zhjcpi 0:aba381fc8158 302 /** GPIO pin to control location chip reset, low level will keep location chip in hibernation state and high level will permit location chip to be activated */
zhjcpi 0:aba381fc8158 303 DigitalOut *pPinReset;
zhjcpi 0:aba381fc8158 304 }tCsrLocConfig;
zhjcpi 0:aba381fc8158 305
zhjcpi 0:aba381fc8158 306 /* General OSP mesasge format */
zhjcpi 0:aba381fc8158 307 typedef struct OspMsg
zhjcpi 0:aba381fc8158 308 {
zhjcpi 0:aba381fc8158 309 CsrUint32 msgId;
zhjcpi 0:aba381fc8158 310 CsrUint32 length;
zhjcpi 0:aba381fc8158 311 CsrUint8 payload[4];
zhjcpi 0:aba381fc8158 312 } tOspMsg;
zhjcpi 0:aba381fc8158 313
zhjcpi 0:aba381fc8158 314 /* keep the internal data of CsrLocation class */
zhjcpi 0:aba381fc8158 315 typedef struct CsrLocInst
zhjcpi 0:aba381fc8158 316 {
zhjcpi 0:aba381fc8158 317 CsrBool bStopFlag;
zhjcpi 1:bbaf9b8d646a 318 CsrBool bPwrModeRsp;
zhjcpi 1:bbaf9b8d646a 319 CsrBool bVerRsp;
zhjcpi 0:aba381fc8158 320
zhjcpi 0:aba381fc8158 321 eCsrLocState locState;
zhjcpi 0:aba381fc8158 322 eProtoState protoState;
zhjcpi 0:aba381fc8158 323 ePowerMode pwrMode;
zhjcpi 0:aba381fc8158 324 CsrUint32 baudRate;
zhjcpi 0:aba381fc8158 325 CsrInt32 computedCheckSum;
zhjcpi 0:aba381fc8158 326 CsrInt32 checksum;
zhjcpi 0:aba381fc8158 327 CsrInt32 msgSize;
zhjcpi 0:aba381fc8158 328 CsrInt32 decodeIndex;
zhjcpi 0:aba381fc8158 329 eProtoDetState protoDetState;
zhjcpi 0:aba381fc8158 330 Timeout *pTimeoutChk; /* timeout process */
zhjcpi 0:aba381fc8158 331 CsrBool bTimeoutFlag;
zhjcpi 0:aba381fc8158 332 eEngineStatus engStatus;
zhjcpi 0:aba381fc8158 333
zhjcpi 0:aba381fc8158 334 tLocSvStatus svStatus; /* 2 kind of messages contribute the svStaus */
zhjcpi 0:aba381fc8158 335
zhjcpi 0:aba381fc8158 336 Serial *pSerialDebug;
zhjcpi 1:bbaf9b8d646a 337 RawSerial *pSerialLoc;
zhjcpi 0:aba381fc8158 338 DigitalOut *pPinOnoff;
zhjcpi 0:aba381fc8158 339 DigitalOut *pPinReset;
zhjcpi 0:aba381fc8158 340
zhjcpi 0:aba381fc8158 341 CsrUint8 serialBuf[MAX_SERIAL_BUF_LEN]; /* buffer the serial data from uart callback function */
zhjcpi 0:aba381fc8158 342 CsrUint8 serialPkt[MAX_SERIAL_PKT_LEN]; /* decoded osp data */
zhjcpi 1:bbaf9b8d646a 343 CsrUint32 in;
zhjcpi 1:bbaf9b8d646a 344 CsrUint32 out;
zhjcpi 0:aba381fc8158 345
zhjcpi 0:aba381fc8158 346 csr_app_output_callback appOutCb;
zhjcpi 0:aba381fc8158 347 csr_app_event_callback appEventCb;
zhjcpi 0:aba381fc8158 348 }tCsrLocInst;
zhjcpi 0:aba381fc8158 349
zhjcpi 0:aba381fc8158 350 /** CsrLocation class.
zhjcpi 0:aba381fc8158 351 * A location interface to control location chip and get position and satellite information.
zhjcpi 0:aba381fc8158 352 */
zhjcpi 0:aba381fc8158 353 class CsrLocation
zhjcpi 0:aba381fc8158 354 {
zhjcpi 0:aba381fc8158 355 public:
zhjcpi 0:aba381fc8158 356 /** Constructor: CsrLocaiton
zhjcpi 0:aba381fc8158 357 * Create the CsrLocation, accept specified configuration
zhjcpi 0:aba381fc8158 358 * @param pLocConfig Configuration including debug serial port, location communication serail port, onoff pin, reset pin
zhjcpi 0:aba381fc8158 359 */
zhjcpi 0:aba381fc8158 360 CsrLocation(tCsrLocConfig *pLocConfig);
zhjcpi 0:aba381fc8158 361
zhjcpi 0:aba381fc8158 362 /** Destructor: CsrLocation
zhjcpi 0:aba381fc8158 363 * Free allocated resource
zhjcpi 0:aba381fc8158 364 */
zhjcpi 0:aba381fc8158 365 ~CsrLocation();
zhjcpi 0:aba381fc8158 366
zhjcpi 0:aba381fc8158 367 /** Register output callback and enent callback functions
zhjcpi 0:aba381fc8158 368 * @param app_output_cb CsrLocation class output the loaction and satellite information to application
zhjcpi 0:aba381fc8158 369 * @param app_event_cb CsrLocation class output the start and stop result to application
zhjcpi 0:aba381fc8158 370 */
zhjcpi 0:aba381fc8158 371 void CsrLocRegOutput(csr_app_output_callback app_output_cb, csr_app_event_callback app_event_cb);
zhjcpi 0:aba381fc8158 372
zhjcpi 0:aba381fc8158 373 /** hw reset to get location chip into hibernation mode */
zhjcpi 0:aba381fc8158 374 void CsrLocReset(void);
zhjcpi 0:aba381fc8158 375
zhjcpi 0:aba381fc8158 376 /** Start location request, activate location chip */
zhjcpi 0:aba381fc8158 377 void CsrLocStart(ePowerMode pwrMode);
zhjcpi 0:aba381fc8158 378
zhjcpi 0:aba381fc8158 379 /** Process location data from chip and update location and satellite information */
zhjcpi 0:aba381fc8158 380 void CsrLocUpdate(void);
zhjcpi 0:aba381fc8158 381
zhjcpi 0:aba381fc8158 382 /** Stop location request, get location chip into hibernation mode */
zhjcpi 0:aba381fc8158 383 void CsrLocStop(void);
zhjcpi 0:aba381fc8158 384
zhjcpi 0:aba381fc8158 385 /** Speical for low power PTF mode.
zhjcpi 0:aba381fc8158 386 * During low power PTF mode, after reporting position, chip will go to hibernation mode automatically.
zhjcpi 0:aba381fc8158 387 * After 30 seconds, chip will recover and report position again. Then chip will go to hibernation mode again.
zhjcpi 0:aba381fc8158 388 * During the hibernation, application can call CsrLocLpmGetPos to get position immediately and no need to wait for the whole interval.
zhjcpi 0:aba381fc8158 389 */
zhjcpi 0:aba381fc8158 390 void CsrLocLpmGetPos(void);
zhjcpi 0:aba381fc8158 391
zhjcpi 0:aba381fc8158 392 /* A debug interface to switch location chip protocol from OSP at 115200bps to NMEA at 4800bps */
zhjcpi 0:aba381fc8158 393 void CsrLocDebugSwitch2Nmea(void);
zhjcpi 0:aba381fc8158 394
zhjcpi 0:aba381fc8158 395 private:
zhjcpi 0:aba381fc8158 396 /* Internal kept data */
zhjcpi 0:aba381fc8158 397 tCsrLocInst csrLocInst;
zhjcpi 0:aba381fc8158 398
zhjcpi 0:aba381fc8158 399 /* Initialize the serial port and open it */
zhjcpi 0:aba381fc8158 400 void _CsrLocUartInit(void);
zhjcpi 0:aba381fc8158 401
zhjcpi 0:aba381fc8158 402 /* Process the raw stream from location seraial port */
zhjcpi 0:aba381fc8158 403 void _CsrLocProcessRawStream(void);
zhjcpi 0:aba381fc8158 404
zhjcpi 0:aba381fc8158 405 /* Detect the OSP protocol outputted from location serial port */
zhjcpi 0:aba381fc8158 406 void _CsrLocDetProtoOsp(CsrUint8 data);
zhjcpi 0:aba381fc8158 407
zhjcpi 0:aba381fc8158 408 /* Detect the NMEA protocol outputted from location serial port */
zhjcpi 0:aba381fc8158 409 void _CsrLocDetProtoNmea(CsrUint8 data);
zhjcpi 0:aba381fc8158 410
zhjcpi 0:aba381fc8158 411 /* Process the raw OSP stream, remove the OSP header, size, check sum, and save the OSP data into interal buffer */
zhjcpi 0:aba381fc8158 412 void _CsrLocProcessRawOspStream(CsrUint8 data);
zhjcpi 0:aba381fc8158 413
zhjcpi 0:aba381fc8158 414 /* Process the saved OSP data and decode them */
zhjcpi 0:aba381fc8158 415 void _CsrLocProcessRawOspPkt(void);
zhjcpi 0:aba381fc8158 416
zhjcpi 0:aba381fc8158 417 /* Calculate the OSP message size to allcate buffer to save the decoded OSP data */
zhjcpi 0:aba381fc8158 418 CsrUint32 _CsrLocCalcMsgSize(void);
zhjcpi 0:aba381fc8158 419
zhjcpi 0:aba381fc8158 420 /* Decode OSP data into pakcet data structure */
zhjcpi 0:aba381fc8158 421 CsrResult _CsrLocDecodeOspPkt( CsrUint8 *payload, CsrUint32 payload_length, CsrUint32 *message_id, void *message_structure, CsrUint32 *message_length);
zhjcpi 0:aba381fc8158 422
zhjcpi 0:aba381fc8158 423 /* Process the decode OSP packet and pass to application when needed */
zhjcpi 0:aba381fc8158 424 void _CsrLocProcessOspPkt(tOspMsg *pOspMsg);
zhjcpi 0:aba381fc8158 425
zhjcpi 0:aba381fc8158 426 /* Timeout process, such as detect OSP and NMEA protocol */
zhjcpi 0:aba381fc8158 427 void _CsrLocTimeout(void);
zhjcpi 0:aba381fc8158 428
zhjcpi 0:aba381fc8158 429 /* Location serial port data recevier */
zhjcpi 0:aba381fc8158 430 void _CsrLocRxHandler(void);
zhjcpi 0:aba381fc8158 431
zhjcpi 0:aba381fc8158 432 /* Send special OSP messges to location chip */
zhjcpi 0:aba381fc8158 433 void _CsrLocSendData(eSendDataType type);
zhjcpi 0:aba381fc8158 434
zhjcpi 0:aba381fc8158 435 /* Trigger a pulse on the onoff pin */
zhjcpi 0:aba381fc8158 436 void _CsrLocHwOnoff(void);
zhjcpi 0:aba381fc8158 437
zhjcpi 0:aba381fc8158 438 /* Trigger a reset on the reset pin */
zhjcpi 0:aba381fc8158 439 void _CsrLocHwReset(void);
zhjcpi 0:aba381fc8158 440 };
zhjcpi 0:aba381fc8158 441
zhjcpi 0:aba381fc8158 442
zhjcpi 0:aba381fc8158 443
zhjcpi 0:aba381fc8158 444 #endif /* CSRLOCATION_H */