GPS-Tracking-Velo
Dependencies: MODSERIAL SDBlockDevice GPS
Forschungsstand und Theoretische Grundlage
Die Bestandteile der Hardware, die das Projekt gebraucht wird, bestehen aus drei Komponente ein Mikrocontroller Board, eine GPS Antenne und ein SIM Modul. GPS basiert auf Satelliten, die mit codierten Radiosignalen ständig ihre aktuelle Position und genaue Uhrzeit ausstrahlen. Aus den Signallaufzeiten können eine GPS Antenne ihre eigene Position und Geschwindigkeit berechnen. Diese GPS Antenne sollte die Daten der Objektposition aus Satelliten auf dem Board gespeichert werden. Diese Daten wurden noch weiter durch eine SIM Module nach GMS Turm und dann per SMS Nachrichten an Handy gesendet. Möglicherweise können diese Daten auch an Webanwendung nach der Sendung an GMS Turm geschickt werden.
mbed-os-example-fat-filesystem-master/main.cpp@2:3d3d272d2df2, 2019-04-16 (annotated)
- Committer:
- QuangAnhLe
- Date:
- Tue Apr 16 21:53:13 2019 +0000
- Revision:
- 2:3d3d272d2df2
- Parent:
- 1:2f617b92078b
- Child:
- 3:eb739df911ef
SMS-test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
QuangAnhLe | 0:ee1ae011cba6 | 1 | #include "mbed.h" |
QuangAnhLe | 1:2f617b92078b | 2 | #include "GPS.h" |
QuangAnhLe | 1:2f617b92078b | 3 | #include <iostream> |
QuangAnhLe | 1:2f617b92078b | 4 | #include <sstream> |
QuangAnhLe | 1:2f617b92078b | 5 | #include <bitset> |
QuangAnhLe | 1:2f617b92078b | 6 | #include <string> |
QuangAnhLe | 0:ee1ae011cba6 | 7 | #include "FATFileSystem.h" |
QuangAnhLe | 0:ee1ae011cba6 | 8 | //#include "HeapBlockDevice.h" |
QuangAnhLe | 0:ee1ae011cba6 | 9 | #include "SDBlockDevice.h" |
QuangAnhLe | 0:ee1ae011cba6 | 10 | #include <stdio.h> |
QuangAnhLe | 0:ee1ae011cba6 | 11 | #include <errno.h> |
QuangAnhLe | 0:ee1ae011cba6 | 12 | |
QuangAnhLe | 0:ee1ae011cba6 | 13 | //HeapBlockDevice bd(128 * 512, 512); |
QuangAnhLe | 0:ee1ae011cba6 | 14 | //SDBlockDevice bd(PinName mosi, PinName miso, PinName sclk, PinName cs); |
QuangAnhLe | 0:ee1ae011cba6 | 15 | SDBlockDevice bd(D11, D12, D13, D10); |
QuangAnhLe | 1:2f617b92078b | 16 | Serial pc(PA_2,PA_3); |
QuangAnhLe | 2:3d3d272d2df2 | 17 | Serial SIM900(PA_9,PA_10); // (TX,RX) |
QuangAnhLe | 1:2f617b92078b | 18 | GPS gps (PA_11,PA_12); |
QuangAnhLe | 0:ee1ae011cba6 | 19 | |
QuangAnhLe | 0:ee1ae011cba6 | 20 | FATFileSystem fs("fs"); |
QuangAnhLe | 2:3d3d272d2df2 | 21 | string result; |
QuangAnhLe | 2:3d3d272d2df2 | 22 | char x; |
QuangAnhLe | 0:ee1ae011cba6 | 23 | |
QuangAnhLe | 0:ee1ae011cba6 | 24 | void return_error(int ret_val){ |
QuangAnhLe | 0:ee1ae011cba6 | 25 | if (ret_val) |
QuangAnhLe | 0:ee1ae011cba6 | 26 | printf("Failure. %d\r\n", ret_val); |
QuangAnhLe | 0:ee1ae011cba6 | 27 | else |
QuangAnhLe | 0:ee1ae011cba6 | 28 | printf("done.\r\n"); |
QuangAnhLe | 0:ee1ae011cba6 | 29 | } |
QuangAnhLe | 1:2f617b92078b | 30 | |
QuangAnhLe | 0:ee1ae011cba6 | 31 | void errno_error(void* ret_val){ |
QuangAnhLe | 0:ee1ae011cba6 | 32 | if (ret_val == NULL) |
QuangAnhLe | 0:ee1ae011cba6 | 33 | printf(" Failure. %d \r\n", errno); |
QuangAnhLe | 0:ee1ae011cba6 | 34 | else |
QuangAnhLe | 0:ee1ae011cba6 | 35 | printf(" done.\r\n"); |
QuangAnhLe | 0:ee1ae011cba6 | 36 | } |
QuangAnhLe | 2:3d3d272d2df2 | 37 | |
QuangAnhLe | 2:3d3d272d2df2 | 38 | void clearString() |
QuangAnhLe | 2:3d3d272d2df2 | 39 | { |
QuangAnhLe | 2:3d3d272d2df2 | 40 | result.clear(); |
QuangAnhLe | 2:3d3d272d2df2 | 41 | } |
QuangAnhLe | 2:3d3d272d2df2 | 42 | |
QuangAnhLe | 2:3d3d272d2df2 | 43 | void callback_rx() { |
QuangAnhLe | 2:3d3d272d2df2 | 44 | |
QuangAnhLe | 2:3d3d272d2df2 | 45 | while (SIM900.readable()) { |
QuangAnhLe | 2:3d3d272d2df2 | 46 | x = SIM900.getc(); |
QuangAnhLe | 2:3d3d272d2df2 | 47 | result += x; |
QuangAnhLe | 2:3d3d272d2df2 | 48 | pc.putc(x); // print the answer from SIM900 |
QuangAnhLe | 2:3d3d272d2df2 | 49 | |
QuangAnhLe | 2:3d3d272d2df2 | 50 | } |
QuangAnhLe | 2:3d3d272d2df2 | 51 | } |
QuangAnhLe | 2:3d3d272d2df2 | 52 | void sendSMS() |
QuangAnhLe | 2:3d3d272d2df2 | 53 | { |
QuangAnhLe | 2:3d3d272d2df2 | 54 | clearString(); |
QuangAnhLe | 2:3d3d272d2df2 | 55 | SIM900.printf("AT+CMGF=1\r"); //at command for send sms |
QuangAnhLe | 2:3d3d272d2df2 | 56 | wait_ms(1000); |
QuangAnhLe | 2:3d3d272d2df2 | 57 | clearString(); |
QuangAnhLe | 2:3d3d272d2df2 | 58 | wait_ms(1000); |
QuangAnhLe | 2:3d3d272d2df2 | 59 | SIM900.printf("AT+CMGS="); |
QuangAnhLe | 2:3d3d272d2df2 | 60 | SIM900.putc('"'); |
QuangAnhLe | 2:3d3d272d2df2 | 61 | SIM900.printf("+4917645651571"); |
QuangAnhLe | 2:3d3d272d2df2 | 62 | SIM900.putc('"'); |
QuangAnhLe | 2:3d3d272d2df2 | 63 | SIM900.printf("\r"); |
QuangAnhLe | 2:3d3d272d2df2 | 64 | wait_ms(1000); |
QuangAnhLe | 2:3d3d272d2df2 | 65 | SIM900.printf("Latitude: %0.6f, Longitude: %0.6f,Altitude: %0.3f",gps.latitude,gps.longitude,gps.altitude); |
QuangAnhLe | 2:3d3d272d2df2 | 66 | wait_ms(1000); |
QuangAnhLe | 2:3d3d272d2df2 | 67 | SIM900.putc(0x1A); |
QuangAnhLe | 2:3d3d272d2df2 | 68 | wait_ms(5000); |
QuangAnhLe | 2:3d3d272d2df2 | 69 | } |
QuangAnhLe | 1:2f617b92078b | 70 | |
QuangAnhLe | 0:ee1ae011cba6 | 71 | int main() { |
QuangAnhLe | 2:3d3d272d2df2 | 72 | /**/ |
QuangAnhLe | 2:3d3d272d2df2 | 73 | pc.printf("\r\n GSM 900 Test\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 74 | SIM900.attach(&callback_rx); |
QuangAnhLe | 2:3d3d272d2df2 | 75 | SIM900.baud(9600); |
QuangAnhLe | 2:3d3d272d2df2 | 76 | wait_ms(100); |
QuangAnhLe | 2:3d3d272d2df2 | 77 | sendSMS(); |
QuangAnhLe | 2:3d3d272d2df2 | 78 | wait_ms(100); |
QuangAnhLe | 2:3d3d272d2df2 | 79 | /**/ |
QuangAnhLe | 0:ee1ae011cba6 | 80 | int error = 0; |
QuangAnhLe | 0:ee1ae011cba6 | 81 | printf("Welcome to the filesystem example.\r\n" |
QuangAnhLe | 0:ee1ae011cba6 | 82 | "Formatting a FAT, RAM-backed filesystem. "); |
QuangAnhLe | 0:ee1ae011cba6 | 83 | error = FATFileSystem::format(&bd); |
QuangAnhLe | 0:ee1ae011cba6 | 84 | return_error(error); |
QuangAnhLe | 1:2f617b92078b | 85 | |
QuangAnhLe | 0:ee1ae011cba6 | 86 | printf("Mounting the filesystem on \"/fs\". "); |
QuangAnhLe | 0:ee1ae011cba6 | 87 | error = fs.mount(&bd); |
QuangAnhLe | 0:ee1ae011cba6 | 88 | return_error(error); |
QuangAnhLe | 1:2f617b92078b | 89 | |
QuangAnhLe | 0:ee1ae011cba6 | 90 | printf("Opening a new file, numbers.txt."); |
QuangAnhLe | 2:3d3d272d2df2 | 91 | FILE* fd = fopen("/fs/numbers.txt", "a+"); |
QuangAnhLe | 0:ee1ae011cba6 | 92 | errno_error(fd); |
QuangAnhLe | 1:2f617b92078b | 93 | |
QuangAnhLe | 2:3d3d272d2df2 | 94 | //for (int i = 0; i < 20; i++){ |
QuangAnhLe | 2:3d3d272d2df2 | 95 | // printf("Writing decimal numbers to a file (%d/20)\r", i); |
QuangAnhLe | 2:3d3d272d2df2 | 96 | //fprintf(fd, "%d\r\n", i); |
QuangAnhLe | 2:3d3d272d2df2 | 97 | //} |
QuangAnhLe | 2:3d3d272d2df2 | 98 | fprintf(fd,"Latitude, Longitude,Altitude,Speed in knots, Date, Time,Number of satellites being tracked, IDs of satellites ins use, Fix, Fix mode\r\n"); |
QuangAnhLe | 1:2f617b92078b | 99 | //printf("Writing decimal numbers to a file (20/20) done.\r\n"); |
QuangAnhLe | 1:2f617b92078b | 100 | |
QuangAnhLe | 0:ee1ae011cba6 | 101 | printf("Closing file."); |
QuangAnhLe | 0:ee1ae011cba6 | 102 | fclose(fd); |
QuangAnhLe | 0:ee1ae011cba6 | 103 | printf(" done.\r\n"); |
QuangAnhLe | 1:2f617b92078b | 104 | |
QuangAnhLe | 0:ee1ae011cba6 | 105 | printf("Re-opening file read-only."); |
QuangAnhLe | 0:ee1ae011cba6 | 106 | fd = fopen("/fs/numbers.txt", "r"); |
QuangAnhLe | 0:ee1ae011cba6 | 107 | errno_error(fd); |
QuangAnhLe | 1:2f617b92078b | 108 | |
QuangAnhLe | 0:ee1ae011cba6 | 109 | printf("Dumping file to screen.\r\n"); |
QuangAnhLe | 0:ee1ae011cba6 | 110 | char buff[16] = {0}; |
QuangAnhLe | 0:ee1ae011cba6 | 111 | while (!feof(fd)){ |
QuangAnhLe | 0:ee1ae011cba6 | 112 | int size = fread(&buff[0], 1, 15, fd); |
QuangAnhLe | 0:ee1ae011cba6 | 113 | fwrite(&buff[0], 1, size, stdout); |
QuangAnhLe | 0:ee1ae011cba6 | 114 | } |
QuangAnhLe | 0:ee1ae011cba6 | 115 | printf("EOF.\r\n"); |
QuangAnhLe | 1:2f617b92078b | 116 | |
QuangAnhLe | 0:ee1ae011cba6 | 117 | printf("Closing file."); |
QuangAnhLe | 0:ee1ae011cba6 | 118 | fclose(fd); |
QuangAnhLe | 0:ee1ae011cba6 | 119 | printf(" done.\r\n"); |
QuangAnhLe | 1:2f617b92078b | 120 | |
QuangAnhLe | 0:ee1ae011cba6 | 121 | printf("Opening root directory."); |
QuangAnhLe | 0:ee1ae011cba6 | 122 | DIR* dir = opendir("/fs/"); |
QuangAnhLe | 0:ee1ae011cba6 | 123 | errno_error(fd); |
QuangAnhLe | 1:2f617b92078b | 124 | |
QuangAnhLe | 0:ee1ae011cba6 | 125 | struct dirent* de; |
QuangAnhLe | 0:ee1ae011cba6 | 126 | printf("Printing all filenames:\r\n"); |
QuangAnhLe | 0:ee1ae011cba6 | 127 | while((de = readdir(dir)) != NULL){ |
QuangAnhLe | 0:ee1ae011cba6 | 128 | printf(" %s\r\n", &(de->d_name)[0]); |
QuangAnhLe | 0:ee1ae011cba6 | 129 | } |
QuangAnhLe | 1:2f617b92078b | 130 | |
QuangAnhLe | 0:ee1ae011cba6 | 131 | printf("Closing root directory. "); |
QuangAnhLe | 0:ee1ae011cba6 | 132 | error = closedir(dir); |
QuangAnhLe | 0:ee1ae011cba6 | 133 | return_error(error); |
QuangAnhLe | 0:ee1ae011cba6 | 134 | printf("Filesystem Demo complete.\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 135 | wait(2); |
QuangAnhLe | 1:2f617b92078b | 136 | while (true) { |
QuangAnhLe | 1:2f617b92078b | 137 | pc.printf("\n"); |
QuangAnhLe | 1:2f617b92078b | 138 | wait(1); |
QuangAnhLe | 1:2f617b92078b | 139 | if(gps.sample()){ |
QuangAnhLe | 1:2f617b92078b | 140 | float latitude = gps.latitude; |
QuangAnhLe | 1:2f617b92078b | 141 | float longitude = gps.longitude; |
QuangAnhLe | 1:2f617b92078b | 142 | float altitude = gps.altitude; |
QuangAnhLe | 2:3d3d272d2df2 | 143 | //float direction =0.0; |
QuangAnhLe | 1:2f617b92078b | 144 | float utc = gps.utc+20000; |
QuangAnhLe | 1:2f617b92078b | 145 | //int sek=gps.sek; |
QuangAnhLe | 1:2f617b92078b | 146 | //int min=gps.min; |
QuangAnhLe | 1:2f617b92078b | 147 | //int hour=gps.hour; |
QuangAnhLe | 1:2f617b92078b | 148 | int sat_tracked=gps. sat_tracked; |
QuangAnhLe | 1:2f617b92078b | 149 | int fix=gps.fix; |
QuangAnhLe | 1:2f617b92078b | 150 | int fix_3d=gps.fix_3d; |
QuangAnhLe | 1:2f617b92078b | 151 | int id1=gps.id1; |
QuangAnhLe | 1:2f617b92078b | 152 | int id2=gps.id2; |
QuangAnhLe | 1:2f617b92078b | 153 | int id3=gps.id3; |
QuangAnhLe | 1:2f617b92078b | 154 | int id4=gps.id4; |
QuangAnhLe | 1:2f617b92078b | 155 | int id5=gps.id5; |
QuangAnhLe | 1:2f617b92078b | 156 | int id6=gps.id6; |
QuangAnhLe | 1:2f617b92078b | 157 | int id7=gps.id7; |
QuangAnhLe | 1:2f617b92078b | 158 | int id8=gps.id8; |
QuangAnhLe | 1:2f617b92078b | 159 | int id9=gps.id9; |
QuangAnhLe | 1:2f617b92078b | 160 | int id10=gps.id10; |
QuangAnhLe | 1:2f617b92078b | 161 | int id11=gps.id11; |
QuangAnhLe | 1:2f617b92078b | 162 | int id12=gps.id12; |
QuangAnhLe | 2:3d3d272d2df2 | 163 | //double hdop=gps.hdop; |
QuangAnhLe | 2:3d3d272d2df2 | 164 | //double pdop=gps.pdop; |
QuangAnhLe | 1:2f617b92078b | 165 | float speed=gps.speed; |
QuangAnhLe | 1:2f617b92078b | 166 | int date=gps.date; |
QuangAnhLe | 1:2f617b92078b | 167 | //char aut=gps.aut; |
QuangAnhLe | 1:2f617b92078b | 168 | //float vdop=gps.vdop; |
QuangAnhLe | 1:2f617b92078b | 169 | //int chek_data=gps.check_data; |
QuangAnhLe | 2:3d3d272d2df2 | 170 | //pc.printf("Latitude, Longitude,Altitude, Direction, Speed in knots, Date, Time, Satellites in use, Satellites in view, IDs of satellites ins use, Fix, Fix mode, PDOP, HDOP\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 171 | //pc.printf("%0.6f,%0.6f,%0.3f,%0.2f,%0.2f,%d,%0.0f,%d,",latitude,longitude,altitude,direction,speed,date,utc, sat_tracked); |
QuangAnhLe | 2:3d3d272d2df2 | 172 | //pc.printf("%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d,",id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,id12); |
QuangAnhLe | 2:3d3d272d2df2 | 173 | //pc.printf("%d,%d,%.2f,%.2f\r\n",fix,fix_3d,pdop,hdop); |
QuangAnhLe | 1:2f617b92078b | 174 | //pc.printf("%d",date); |
QuangAnhLe | 1:2f617b92078b | 175 | pc.printf("Latitude: %0.6f\r\n",latitude); |
QuangAnhLe | 1:2f617b92078b | 176 | pc.printf("Longitude:%0.6f\r\n",longitude); |
QuangAnhLe | 1:2f617b92078b | 177 | pc.printf("Altitude: %0.3f\r\n",altitude); |
QuangAnhLe | 1:2f617b92078b | 178 | pc.printf("Speed in knots: %0.2f\r\n",speed); |
QuangAnhLe | 1:2f617b92078b | 179 | pc.printf("Date: %d\r\n",date); |
QuangAnhLe | 1:2f617b92078b | 180 | pc.printf("Time UTC: %0.0f\r\n",utc); |
QuangAnhLe | 1:2f617b92078b | 181 | pc.printf("Number of satellites being tracked: %d\r\n", sat_tracked); |
QuangAnhLe | 1:2f617b92078b | 182 | pc.printf("PRNs of satellites used for fix:\r\n"); |
QuangAnhLe | 1:2f617b92078b | 183 | pc.printf("ID1:%d,ID2:%d,ID3:%d,ID4:%d,ID5:%d,ID6:%d\r\n",id1,id2,id3,id4,id5,id6); |
QuangAnhLe | 1:2f617b92078b | 184 | pc.printf("ID7:%d,ID8:%d,ID9:%d,ID10:%d,ID11:%d,ID12:%d\r\n",id7,id8,id9,id10,id11,id12); |
QuangAnhLe | 1:2f617b92078b | 185 | pc.printf("Fix quality: %d - value include 0=invalid; 1=GPS fix\r\n",fix); |
QuangAnhLe | 1:2f617b92078b | 186 | pc.printf("3D fix: %d - value include: 1 = no fix, 2 = 2D fix, 3 = 3D fix\r\n\n", fix_3d); |
QuangAnhLe | 1:2f617b92078b | 187 | pc.printf("****************************************************************\r\n"); |
QuangAnhLe | 1:2f617b92078b | 188 | |
QuangAnhLe | 1:2f617b92078b | 189 | FILE* fd = fopen("/fs/numbers.txt", "a+"); |
QuangAnhLe | 2:3d3d272d2df2 | 190 | //errno_error(fd); |
QuangAnhLe | 2:3d3d272d2df2 | 191 | if(fd != NULL) |
QuangAnhLe | 2:3d3d272d2df2 | 192 | { |
QuangAnhLe | 2:3d3d272d2df2 | 193 | printf("write file.\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 194 | fprintf(fd,"%0.6f,%0.6f,%0.3f,%0.2f,%d,%0.0f,%d,%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d,%d,%d\r\n",latitude, longitude, altitude, speed, date, utc, sat_tracked, id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,id12, fix,fix_3d); |
QuangAnhLe | 2:3d3d272d2df2 | 195 | //fclose(fd); |
QuangAnhLe | 2:3d3d272d2df2 | 196 | printf("Closing file.\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 197 | fclose(fd); |
QuangAnhLe | 2:3d3d272d2df2 | 198 | printf(" done.\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 199 | } |
QuangAnhLe | 1:2f617b92078b | 200 | |
QuangAnhLe | 2:3d3d272d2df2 | 201 | //printf("Re-opening file read-only."); |
QuangAnhLe | 2:3d3d272d2df2 | 202 | //fd = fopen("/fs/numbers.txt", "r"); |
QuangAnhLe | 2:3d3d272d2df2 | 203 | //errno_error(fd); |
QuangAnhLe | 2:3d3d272d2df2 | 204 | |
QuangAnhLe | 2:3d3d272d2df2 | 205 | wait(1); |
QuangAnhLe | 2:3d3d272d2df2 | 206 | //for (int i = 0; i < 20; i++){ |
QuangAnhLe | 2:3d3d272d2df2 | 207 | // printf("Writing decimal numbers to a file (%d/20)\r", i); |
QuangAnhLe | 2:3d3d272d2df2 | 208 | //fprintf(fd, "%d\r\n", i); |
QuangAnhLe | 2:3d3d272d2df2 | 209 | //} |
QuangAnhLe | 1:2f617b92078b | 210 | //fprintf(fd,"Latitude, Longitude,Altitude,Speed in knots, Date, Time,Number of satellites being tracked, IDs of satellites ins use, Fix, Fix mode,\r\n"); |
QuangAnhLe | 2:3d3d272d2df2 | 211 | //fprintf(fd,"%0.6f,%0.6f,%0.3f,%0.2f,%d,%0.0f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",latitude, longitude, altitude, speed, date, utc, sat_tracked, id1,id2,id3,id4,id5,id6,id7,id8,id9,id10,id11,id12, fix,fix_3d); |
QuangAnhLe | 1:2f617b92078b | 212 | } |
QuangAnhLe | 2:3d3d272d2df2 | 213 | } |
QuangAnhLe | 1:2f617b92078b | 214 | } |