main.cpp
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "mbed.h"
#define LENGTH 112
#define BAUD 9600
I2C i2c(D14, D15, BAUD);
DigitalOut led1(LED1);
Serial pc(SERIAL_TX, SERIAL_RX);
unsigned char adress_DSGPM;//= 0xD0, 0xD1, 0xD2 ou 0xD3 en fonction des jumpers branchés sur le GPS
char data[LENGTH];
bool findGPSDevices();
int main()
{
pc.printf("starting...");
if(findGPSDevices()){
char BaseReg_Address = 0;
char cmd[1]={BaseReg_Address};
while(1)
{
led1 = 1;
wait(0.2);
i2c.write(adress_DSGPM, cmd, 1);
i2c.read(adress_DSGPM, data, LENGTH);
pc.printf("Time : %d%d:%d%d:%d%d\n", data[0], data[1], data[2], data[3], data[4], data[5]);
pc.printf("Date : %d%d/%d%d/%d%d%d%d\n", data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13]);
pc.printf("Latitude : %d%d degres\n", data[14], data[15]);
pc.printf("Longitude : %d%d%d degres\n", data[23], data[24], data[25]);
pc.printf("Altitude : %d%d%d%d%d metres\n\n", data[39], data[40], data[41], data[42], data[43]);
led1 = 0;
wait(0.5);
}
}
}
/*
* Permet de trouver les GPS et leurs adresses. Assigne une adresse trouvée à
* la variable 'adress_DSGPM'.
*/
bool findGPSDevices() {
int count = 0;
bool res = false;
pc.printf("Searching for I2C devices...\n");
for (int address=0xD0; address<0xD7; address+=2)
{
if (!i2c.write(address, NULL, 0)) //0 est renvoyé = GPS trouvé
{
pc.printf(" - I2C device found at address 0x%02X\n", address);
adress_DSGPM = address;
res = true;
count++;
}
}
pc.printf("%d devices found\n\n", count);
return res;
}