trying to make telnetserver repo public
Fork of MODGPS by
example2.cpp@2:8aa059e7d8b1, 2011-04-15 (annotated)
- Committer:
- AjK
- Date:
- Fri Apr 15 12:23:52 2011 +0000
- Revision:
- 2:8aa059e7d8b1
- Parent:
- 0:db98027c0bbb
1.12 See ChangeLog.c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 2:8aa059e7d8b1 | 1 | #ifdef COMPILE_EXAMPLE2_CODE_MODGPS |
AjK | 0:db98027c0bbb | 2 | |
AjK | 0:db98027c0bbb | 3 | #include "mbed.h" |
AjK | 0:db98027c0bbb | 4 | #include "GPS.h" |
AjK | 0:db98027c0bbb | 5 | |
AjK | 0:db98027c0bbb | 6 | Serial pc(USBTX, USBRX); |
AjK | 0:db98027c0bbb | 7 | DigitalOut led1(LED1); |
AjK | 0:db98027c0bbb | 8 | DigitalOut led2(LED2); |
AjK | 0:db98027c0bbb | 9 | DigitalOut led3(LED3); |
AjK | 0:db98027c0bbb | 10 | DigitalOut led4(LED4); |
AjK | 0:db98027c0bbb | 11 | |
AjK | 0:db98027c0bbb | 12 | Timeout t2, t3, t4; |
AjK | 0:db98027c0bbb | 13 | |
AjK | 0:db98027c0bbb | 14 | void t2out(void) { led2 = 0; } |
AjK | 0:db98027c0bbb | 15 | void t3out(void) { led3 = 0; } |
AjK | 0:db98027c0bbb | 16 | void t4out(void) { led4 = 0; } |
AjK | 0:db98027c0bbb | 17 | |
AjK | 0:db98027c0bbb | 18 | void blip2(void) { led2 = 1; t2.attach(&t2out, 0.1); } |
AjK | 0:db98027c0bbb | 19 | void blip3(void) { led3 = 1; t3.attach(&t3out, 0.1); } |
AjK | 0:db98027c0bbb | 20 | void blip4(void) { led4 = 1; t4.attach(&t4out, 0.1); } |
AjK | 0:db98027c0bbb | 21 | |
AjK | 0:db98027c0bbb | 22 | int main() { |
AjK | 0:db98027c0bbb | 23 | GPS *gps = new GPS(NC, p25); |
AjK | 0:db98027c0bbb | 24 | GPS_Time q1; |
AjK | 0:db98027c0bbb | 25 | GPS_Geodetic *geo; |
AjK | 0:db98027c0bbb | 26 | |
AjK | 0:db98027c0bbb | 27 | pc.baud(115200); |
AjK | 0:db98027c0bbb | 28 | |
AjK | 0:db98027c0bbb | 29 | gps->baud(9600); |
AjK | 0:db98027c0bbb | 30 | gps->format(8, Serial::None, 1); |
AjK | 0:db98027c0bbb | 31 | |
AjK | 0:db98027c0bbb | 32 | gps->ppsAttach(p29, GPS::ppsFall); |
AjK | 0:db98027c0bbb | 33 | |
AjK | 0:db98027c0bbb | 34 | gps->attach_pps(&blip2); |
AjK | 0:db98027c0bbb | 35 | gps->attach_gga(&blip3); |
AjK | 0:db98027c0bbb | 36 | gps->attach_rmc(&blip4); |
AjK | 0:db98027c0bbb | 37 | |
AjK | 0:db98027c0bbb | 38 | while(1) { |
AjK | 0:db98027c0bbb | 39 | // Every 3 seconds, flip LED1 and print the basic GPS info. |
AjK | 0:db98027c0bbb | 40 | wait(3); |
AjK | 0:db98027c0bbb | 41 | flip1(); |
AjK | 0:db98027c0bbb | 42 | pc.printf("Method 1. Lat = %.4f ", gps->latitude()); |
AjK | 0:db98027c0bbb | 43 | pc.printf("Lon = %.4f ", gps->longitude()); |
AjK | 0:db98027c0bbb | 44 | pc.printf("Alt = %.4f ", gps->altitude()); |
AjK | 0:db98027c0bbb | 45 | gps->timeNow(&q1); |
AjK | 0:db98027c0bbb | 46 | pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", |
AjK | 0:db98027c0bbb | 47 | q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year); |
AjK | 0:db98027c0bbb | 48 | |
AjK | 0:db98027c0bbb | 49 | // Alternative method that does the same thing. |
AjK | 0:db98027c0bbb | 50 | geo = gps->geodetic(); |
AjK | 0:db98027c0bbb | 51 | pc.printf("Method 2. Lat = %.4f ", geo->lat); |
AjK | 0:db98027c0bbb | 52 | pc.printf("Lon = %.4f ", geo->lon); |
AjK | 0:db98027c0bbb | 53 | pc.printf("Alt = %.4f ", geo->alt); |
AjK | 0:db98027c0bbb | 54 | delete(geo); |
AjK | 0:db98027c0bbb | 55 | |
AjK | 0:db98027c0bbb | 56 | GPS_Time *q2 = gps->timeNow(); |
AjK | 0:db98027c0bbb | 57 | pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n\n", |
AjK | 0:db98027c0bbb | 58 | q2->hour, q2->minute, q2->second, q2->day, q2->month, q2->year); |
AjK | 0:db98027c0bbb | 59 | delete(q2); |
AjK | 0:db98027c0bbb | 60 | } |
AjK | 0:db98027c0bbb | 61 | } |
AjK | 0:db98027c0bbb | 62 | |
AjK | 0:db98027c0bbb | 63 | #endif |