Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __DGPS_H__
00013 #define __DGPS_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma systemFile
00039
00040 #ifndef __COMMON_H__
00041 #include "common.h"
00042 #endif
00043
00044 #define DGPS_I2C_ADDR 0x06
00045 #define DGPS_CMD_UTC 0x00
00046 #define DGPS_CMD_STATUS 0x01
00047 #define DGPS_CMD_LAT 0x02
00048 #define DGPS_CMD_LONG 0x04
00049 #define DGPS_CMD_VELO 0x06
00050 #define DGPS_CMD_HEAD 0x07
00051 #define DGPS_CMD_DIST 0x08
00052 #define DGPS_CMD_ANGD 0x09
00053 #define DGPS_CMD_ANGR 0x0A
00054 #define DGPS_CMD_SLAT 0x0B
00055 #define DGPS_CMD_SLONG 0x0C
00056
00057
00058 bool DGPSreadStatus(tSensors link);
00059 long DGPSreadUTC(tSensors link);
00060 long DGPSreadLatitude(tSensors link);
00061 long DGPSreadLongitude(tSensors link);
00062 int DGPSreadVelocity(tSensors link);
00063 int DGPSreadHeading(tSensors link);
00064 int DGPSreadRelHeading(tSensors link);
00065 int DGPSreadTravHeading(tSensors link);
00066 bool DGPSsetDestination(tSensors link, long latitude, long longitude);
00067 int DGPSreadDistToDestination(tSensors link);
00068
00069 tByteArray DGPS_I2CRequest;
00070 tByteArray DGPS_I2CReply;
00071
00072 long _DGPSreadRegister(tSensors link, unsigned byte command, int replysize) {
00073 memset(DGPS_I2CRequest, 0, sizeof(tByteArray));
00074
00075 DGPS_I2CRequest[0] = 2;
00076 DGPS_I2CRequest[1] = DGPS_I2C_ADDR;
00077 DGPS_I2CRequest[2] = command;
00078
00079 if (!writeI2C(link, DGPS_I2CRequest, DGPS_I2CReply, 4))
00080 return -1;
00081
00082
00083 if (replysize == 4)
00084 return (long)DGPS_I2CReply[3] + ((long)DGPS_I2CReply[2] << 8) + ((long)DGPS_I2CReply[1] << 16) + ((long)DGPS_I2CReply[0] << 24);
00085 else if (replysize == 3)
00086 return (long)DGPS_I2CReply[2] + ((long)DGPS_I2CReply[1] << 8) + ((long)DGPS_I2CReply[0] << 16);
00087 else if (replysize == 2)
00088 return (long)DGPS_I2CReply[1] + ((long)DGPS_I2CReply[0] << 8);
00089 else if (replysize == 1)
00090 return (long)DGPS_I2CReply[0];
00091
00092 return 0;
00093 }
00094
00095
00096 bool DGPSreadStatus(tSensors link) {
00097 return (_DGPSreadRegister(link, DGPS_CMD_STATUS, 1) == 1) ? true : false;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 long DGPSreadUTC(tSensors link) {
00107 return _DGPSreadRegister(link, DGPS_CMD_UTC, 4);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 long DGPSreadLatitude(tSensors link) {
00117 return _DGPSreadRegister(link, DGPS_CMD_LAT, 4);
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 long DGPSreadLongitude(tSensors link) {
00127 return _DGPSreadRegister(link, DGPS_CMD_LONG, 4);
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 int DGPSreadVelocity(tSensors link) {
00137 return _DGPSreadRegister(link, DGPS_CMD_VELO, 3);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 int DGPSreadHeading(tSensors link) {
00147 return _DGPSreadRegister(link, DGPS_CMD_HEAD, 2);
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 int DGPSreadRelHeading(tSensors link) {
00157 return _DGPSreadRegister(link, DGPS_CMD_ANGD, 2);
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167 int DGPSreadTravHeading(tSensors link) {
00168 return _DGPSreadRegister(link, DGPS_CMD_ANGR, 2);
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 bool DGPSsetDestination(tSensors link, long latitude, long longitude) {
00180 memset(DGPS_I2CRequest, 0, sizeof(tByteArray));
00181
00182
00183 DGPS_I2CRequest[0] = 2;
00184 DGPS_I2CRequest[1] = DGPS_I2C_ADDR;
00185 DGPS_I2CRequest[2] = DGPS_CMD_SLAT;
00186 DGPS_I2CRequest[3] = (latitude >> 24) & 0xFF;
00187 DGPS_I2CRequest[4] = (latitude >> 16) & 0xFF;
00188 DGPS_I2CRequest[5] = (latitude >> 8) & 0xFF;
00189 DGPS_I2CRequest[6] = (latitude >> 0) & 0xFF;
00190 if (!writeI2C(link, DGPS_I2CRequest))
00191 return false;
00192
00193 wait1Msec(100);
00194
00195
00196 DGPS_I2CRequest[0] = 2;
00197 DGPS_I2CRequest[1] = DGPS_I2C_ADDR;
00198 DGPS_I2CRequest[2] = DGPS_CMD_SLONG;
00199 DGPS_I2CRequest[3] = (longitude >> 24) & 0xFF;
00200 DGPS_I2CRequest[4] = (longitude >> 16) & 0xFF;
00201 DGPS_I2CRequest[5] = (longitude >> 8) & 0xFF;
00202 DGPS_I2CRequest[6] = (longitude >> 0) & 0xFF;
00203
00204 return writeI2C(link, DGPS_I2CRequest);
00205 }
00206
00207
00208
00209
00210
00211
00212
00213 int DGPSreadDistToDestination(tSensors link) {
00214 return _DGPSreadRegister(link, DGPS_CMD_DIST, 4);
00215 }
00216
00217 #endif // __DGPS_H__
00218
00219
00220
00221
00222
00223