hardware/gps
Revisión | 7bd7c2c228553b12c610f07d9c69d5d4165b37c2 (tree) |
---|---|
Tiempo | 2015-03-23 16:22:28 |
Autor | Keith Conger <keith.conger@gmai...> |
Commiter | Chih-Wei Huang |
*Fixed accuracy *Add property for baud rate
@@ -1,7 +1,7 @@ | ||
1 | -/* //hardware/hw/gps/gps_freerunner.c | |
2 | -** | |
1 | +/* | |
3 | 2 | ** Copyright 2006, The Android Open Source Project |
4 | 3 | ** Copyright 2009, Michael Trimarchi <michael@panicking.kicks-ass.org> |
4 | +** Copyright 2015, Keith Conger <keith.conger@gmail.com> | |
5 | 5 | ** |
6 | 6 | ** This program is free software; you can redistribute it and/or modify it under |
7 | 7 | ** the terms of the GNU General Public License as published by the Free |
@@ -28,7 +28,7 @@ | ||
28 | 28 | #include <signal.h> |
29 | 29 | #include <unistd.h> |
30 | 30 | |
31 | -#define LOG_TAG "gps_gj" | |
31 | +#define LOG_TAG "gps_serial" | |
32 | 32 | |
33 | 33 | #include <cutils/log.h> |
34 | 34 | #include <cutils/sockets.h> |
@@ -61,7 +61,7 @@ static int id_in_fixed[12]; | ||
61 | 61 | #define GPS_DEV_HIGH_UPDATE_RATE (1) |
62 | 62 | |
63 | 63 | #define GPS_DEV_LOW_BAUD (B9600) |
64 | -#define GPS_DEV_HIGH_BAUD (B19200) | |
64 | +#define GPS_DEV_HIGH_BAUD (B115200) | |
65 | 65 | static void gps_dev_init(int fd); |
66 | 66 | static void gps_dev_deinit(int fd); |
67 | 67 | static void gps_dev_start(int fd); |
@@ -104,7 +104,7 @@ nmea_tokenizer_init( NmeaTokenizer* t, const char* p, const char* end ) | ||
104 | 104 | end -= 1; |
105 | 105 | } |
106 | 106 | |
107 | - // get rid of checksum at the end of the sentecne | |
107 | + // get rid of checksum at the end of the sentence | |
108 | 108 | if (end >= p+3 && end[-3] == '*') { |
109 | 109 | end -= 3; |
110 | 110 | } |
@@ -146,7 +146,6 @@ nmea_tokenizer_get( NmeaTokenizer* t, int index ) | ||
146 | 146 | return tok; |
147 | 147 | } |
148 | 148 | |
149 | - | |
150 | 149 | static int |
151 | 150 | str2int( const char* p, const char* end ) |
152 | 151 | { |
@@ -193,7 +192,6 @@ str2float( const char* p, const char* end ) | ||
193 | 192 | /*****************************************************************/ |
194 | 193 | /*****************************************************************/ |
195 | 194 | |
196 | -//#define NMEA_MAX_SIZE 83 | |
197 | 195 | #define NMEA_MAX_SIZE 255 |
198 | 196 | |
199 | 197 | typedef struct { |
@@ -417,6 +415,25 @@ nmea_reader_update_altitude( NmeaReader* r, | ||
417 | 415 | } |
418 | 416 | |
419 | 417 | |
418 | +static int nmea_reader_update_accuracy( NmeaReader* r, | |
419 | + Token accuracy ) | |
420 | +{ | |
421 | + double acc; | |
422 | + Token tok = accuracy; | |
423 | + | |
424 | + if (tok.p >= tok.end) | |
425 | + return -1; | |
426 | + | |
427 | + r->fix.accuracy = str2float(tok.p, tok.end); | |
428 | + if (r->fix.accuracy == 99.99){ | |
429 | + return 0; | |
430 | + } | |
431 | + | |
432 | + r->fix.flags |= GPS_LOCATION_HAS_ACCURACY; | |
433 | + return 0; | |
434 | +} | |
435 | + | |
436 | + | |
420 | 437 | static int |
421 | 438 | nmea_reader_update_bearing( NmeaReader* r, |
422 | 439 | Token bearing ) |
@@ -487,8 +504,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
487 | 504 | _gps_state->callbacks->nmea_cb(tv.tv_sec*1000+tv.tv_usec/1000, r->in, r->pos); |
488 | 505 | |
489 | 506 | nmea_tokenizer_init(tzer, r->in, r->in + r->pos); |
490 | -//#if GPS_DEBUG | |
491 | -#if 0 | |
507 | +#if GPS_DEBUG | |
492 | 508 | { |
493 | 509 | int n; |
494 | 510 | D("Found %d tokens", tzer->count); |
@@ -504,14 +520,6 @@ nmea_reader_parse( NmeaReader* r ) | ||
504 | 520 | D("sentence id '%.*s' too short, ignored.", tok.end-tok.p, tok.p); |
505 | 521 | return; |
506 | 522 | } |
507 | -/* | |
508 | -$GPRMC,084537.345,V,,,,,,,270811,,,N*4F | |
509 | -$GPGGA,084538.353,,,,,0,00,,,M,0.0,M,,0000*51 | |
510 | -$GPGSA,A,1,,,,,,,,,,,,,,,*1E | |
511 | -$GPGSV,3,1,11,09,80,303,,12,41,229,,15,40,178,,17,39,070,*70 | |
512 | -$GPGSV,3,2,11,22,20,295,,18,18,256,,14,13,317,,26,10,154,*72 | |
513 | -$GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | |
514 | -*/ | |
515 | 523 | // ignore first two characters. |
516 | 524 | tok.p += 2; |
517 | 525 | if ( !memcmp(tok.p, "GGA", 3) ) { |
@@ -521,6 +529,7 @@ $GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | ||
521 | 529 | Token tok_latitudeHemi = nmea_tokenizer_get(tzer,3); |
522 | 530 | Token tok_longitude = nmea_tokenizer_get(tzer,4); |
523 | 531 | Token tok_longitudeHemi = nmea_tokenizer_get(tzer,5); |
532 | + Token tok_accuracy = nmea_tokenizer_get(tzer,8); | |
524 | 533 | Token tok_altitude = nmea_tokenizer_get(tzer,9); |
525 | 534 | Token tok_altitudeUnits = nmea_tokenizer_get(tzer,10); |
526 | 535 |
@@ -531,6 +540,8 @@ $GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | ||
531 | 540 | tok_longitudeHemi.p[0]); |
532 | 541 | nmea_reader_update_altitude(r, tok_altitude, tok_altitudeUnits); |
533 | 542 | |
543 | + nmea_reader_update_accuracy(r, tok_accuracy); | |
544 | + | |
534 | 545 | } else if ( !memcmp(tok.p, "GSA", 3) ) { |
535 | 546 | //Satellites are handled by RPC-side code. |
536 | 547 | /* |
@@ -552,6 +563,7 @@ $GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | ||
552 | 563 | Token tok_pdop = nmea_tokenizer_get(tzer,15); |
553 | 564 | Token tok_hdop = nmea_tokenizer_get(tzer,16); |
554 | 565 | Token tok_vdop = nmea_tokenizer_get(tzer,17); |
566 | + | |
555 | 567 | int i; |
556 | 568 | for ( i=0; i<12; i++ ) { |
557 | 569 | Token tok_id = nmea_tokenizer_get(tzer,3+i); |
@@ -641,12 +653,25 @@ $GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | ||
641 | 653 | nmea_reader_update_bearing( r, tok_bearing ); |
642 | 654 | nmea_reader_update_speed ( r, tok_speed ); |
643 | 655 | } |
656 | + } else if ( !memcmp(tok.p, "VTG", 3) ) { | |
657 | + Token tok_fixStatus = nmea_tokenizer_get(tzer,9); | |
658 | + | |
659 | + if (tok_fixStatus.p[0] != '\0' && tok_fixStatus.p[0] != 'N') { | |
660 | + Token tok_bearing = nmea_tokenizer_get(tzer,1); | |
661 | + Token tok_speed = nmea_tokenizer_get(tzer,5); | |
662 | + | |
663 | + nmea_reader_update_bearing( r, tok_bearing ); | |
664 | + nmea_reader_update_speed ( r, tok_speed ); | |
665 | + } | |
644 | 666 | } else { |
645 | 667 | tok.p -= 2; |
646 | 668 | D("unknown sentence '%.*s", tok.end-tok.p, tok.p); |
647 | 669 | } |
648 | - if (r->fix.flags != 0) { | |
670 | + | |
671 | + | |
649 | 672 | #if GPS_DEBUG |
673 | + if (r->fix.flags) { | |
674 | + | |
650 | 675 | char temp[256]; |
651 | 676 | char* p = temp; |
652 | 677 | char* end = p + sizeof(temp); |
@@ -670,22 +695,16 @@ $GPGSV,3,3,11,25,08,234,,28,08,056,,24,04,011,*40 | ||
670 | 695 | } |
671 | 696 | gmtime_r( (time_t*) &r->fix.timestamp, &utc ); |
672 | 697 | p += snprintf(p, end-p, " time=%s", asctime( &utc ) ); |
698 | + ALOGD("%s\n", temp); | |
699 | + } | |
673 | 700 | #endif |
674 | - if (_gps_state->callbacks->location_cb) { | |
675 | - _gps_state->callbacks->location_cb( &r->fix ); | |
676 | - r->fix.flags = 0; | |
677 | - } else { | |
678 | - D("no callback, keeping data until needed !"); | |
679 | - } | |
680 | - | |
681 | -/* | |
682 | - if (r->callback) { | |
683 | - r->callback( &r->fix ); | |
701 | + if (r->fix.flags & GPS_LOCATION_HAS_ACCURACY) { | |
702 | + if (_gps_state->callbacks->location_cb) { | |
703 | + _gps_state->callbacks->location_cb( &r->fix ); | |
684 | 704 | r->fix.flags = 0; |
685 | 705 | } else { |
686 | 706 | D("no callback, keeping data until needed !"); |
687 | 707 | } |
688 | -*/ | |
689 | 708 | } |
690 | 709 | } |
691 | 710 |
@@ -729,10 +748,6 @@ enum { | ||
729 | 748 | CMD_STOP = 2 |
730 | 749 | }; |
731 | 750 | |
732 | - | |
733 | - | |
734 | - | |
735 | - | |
736 | 751 | static void |
737 | 752 | gps_state_done( GpsState* s ) |
738 | 753 | { |
@@ -845,7 +860,6 @@ gps_state_thread( void* arg ) | ||
845 | 860 | ALOGE("epoll_wait() unexpected error: %s", strerror(errno)); |
846 | 861 | continue; |
847 | 862 | } |
848 | -// D("gps thread received %d events", nevents); | |
849 | 863 | for (ne = 0; ne < nevents; ne++) { |
850 | 864 | if ((events[ne].events & (EPOLLERR|EPOLLHUP)) != 0) { |
851 | 865 | ALOGE("EPOLLERR or EPOLLHUP after epoll_wait() !?"); |
@@ -882,7 +896,6 @@ gps_state_thread( void* arg ) | ||
882 | 896 | } |
883 | 897 | } else if (fd == gps_fd) { |
884 | 898 | char buff[32]; |
885 | -// D("gps fd event"); | |
886 | 899 | for (;;) { |
887 | 900 | int nn, ret; |
888 | 901 |
@@ -894,11 +907,9 @@ gps_state_thread( void* arg ) | ||
894 | 907 | ALOGE("error while reading from gps daemon socket: %s:", strerror(errno)); |
895 | 908 | break; |
896 | 909 | } |
897 | -// D("received %d bytes: %.*s", ret, ret, buff); | |
898 | 910 | for (nn = 0; nn < ret; nn++) |
899 | 911 | nmea_reader_addc( reader, buff[nn] ); |
900 | 912 | } |
901 | -// D("gps fd event end"); | |
902 | 913 | } else { |
903 | 914 | ALOGE("epoll_wait() returned unkown fd %d ?", fd); |
904 | 915 | } |
@@ -912,6 +923,7 @@ static void | ||
912 | 923 | gps_state_init( GpsState* state, GpsCallbacks* callbacks ) |
913 | 924 | { |
914 | 925 | char prop[PROPERTY_VALUE_MAX]; |
926 | + char baud[PROPERTY_VALUE_MAX]; | |
915 | 927 | char device[256]; |
916 | 928 | int ret; |
917 | 929 | int done = 0; |
@@ -932,10 +944,6 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
932 | 944 | return; |
933 | 945 | } |
934 | 946 | |
935 | - //if ( snprintf(device, sizeof(device), "/dev/%s", prop) >= (int)sizeof(device) ) { | |
936 | - // ALOGE("gps serial device name too long: '%s'", prop); | |
937 | - // return; | |
938 | - //} | |
939 | 947 | snprintf(device, sizeof(device), "/dev/%s",prop); |
940 | 948 | do { |
941 | 949 | state->fd = open( device, O_RDWR ); |
@@ -956,10 +964,29 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
956 | 964 | ios.c_oflag &= (~ONLCR); /* Stop \n -> \r\n translation on output */ |
957 | 965 | ios.c_iflag &= (~(ICRNL | INLCR)); /* Stop \r -> \n & \n -> \r translation on input */ |
958 | 966 | ios.c_iflag |= (IGNCR | IXOFF); /* Ignore \r & XON/XOFF on input */ |
959 | - ios.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD; // baud 115200, cs8 | |
960 | -//GJ | |
967 | + // set baud rate and other flags | |
968 | + property_get("ro.kernel.android.gpsttybaud",baud,"9600"); | |
969 | + if (strcmp(baud, "9600") == 0) { | |
970 | + ALOGE("setting gps baud rate to 9600"); | |
971 | + ios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD; | |
972 | + } else if (strcmp(baud, "19200") == 0) { | |
973 | + ALOGE("setting gps baud rate to 19200"); | |
974 | + ios.c_cflag = B19200 | CRTSCTS | CS8 | CLOCAL | CREAD; | |
975 | + } else if (strcmp(baud, "38400") == 0) { | |
976 | + ALOGE("setting gps baud rate to 38400"); | |
977 | + ios.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD; | |
978 | + } else if (strcmp(baud, "57600") == 0) { | |
979 | + ALOGE("setting gps baud rate to 57600"); | |
980 | + ios.c_cflag = B57600 | CRTSCTS | CS8 | CLOCAL | CREAD; | |
981 | + } else if (strcmp(baud, "115200") == 0) { | |
982 | + ALOGE("setting gps baud rate to 115200"); | |
983 | + ios.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD; | |
984 | + } else { | |
985 | + ALOGE("gps baud rate unknown: '%s'", baud); | |
986 | + return; | |
987 | + } | |
988 | + | |
961 | 989 | tcsetattr( state->fd, TCSANOW, &ios ); |
962 | -//EGJ | |
963 | 990 | } |
964 | 991 | |
965 | 992 | if ( socketpair( AF_LOCAL, SOCK_STREAM, 0, state->control ) < 0 ) { |
@@ -993,9 +1020,9 @@ Fail: | ||
993 | 1020 | |
994 | 1021 | |
995 | 1022 | static int |
996 | -freerunner_gps_init(GpsCallbacks* callbacks) | |
1023 | +serial_gps_init(GpsCallbacks* callbacks) | |
997 | 1024 | { |
998 | - D("freerunner_gps_init"); | |
1025 | + D("serial_gps_init"); | |
999 | 1026 | GpsState* s = _gps_state; |
1000 | 1027 | |
1001 | 1028 | if (!s->init) |
@@ -1004,13 +1031,11 @@ freerunner_gps_init(GpsCallbacks* callbacks) | ||
1004 | 1031 | if (s->fd < 0) |
1005 | 1032 | return -1; |
1006 | 1033 | |
1007 | - | |
1008 | - | |
1009 | 1034 | return 0; |
1010 | 1035 | } |
1011 | 1036 | |
1012 | 1037 | static void |
1013 | -freerunner_gps_cleanup(void) | |
1038 | +serial_gps_cleanup(void) | |
1014 | 1039 | { |
1015 | 1040 | GpsState* s = _gps_state; |
1016 | 1041 |
@@ -1020,7 +1045,7 @@ freerunner_gps_cleanup(void) | ||
1020 | 1045 | |
1021 | 1046 | |
1022 | 1047 | static int |
1023 | -freerunner_gps_start() | |
1048 | +serial_gps_start() | |
1024 | 1049 | { |
1025 | 1050 | GpsState* s = _gps_state; |
1026 | 1051 |
@@ -1036,7 +1061,7 @@ freerunner_gps_start() | ||
1036 | 1061 | |
1037 | 1062 | |
1038 | 1063 | static int |
1039 | -freerunner_gps_stop() | |
1064 | +serial_gps_stop() | |
1040 | 1065 | { |
1041 | 1066 | GpsState* s = _gps_state; |
1042 | 1067 |
@@ -1052,32 +1077,28 @@ freerunner_gps_stop() | ||
1052 | 1077 | |
1053 | 1078 | |
1054 | 1079 | static int |
1055 | -freerunner_gps_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty) | |
1080 | +serial_gps_inject_time(GpsUtcTime time, int64_t timeReference, int uncertainty) | |
1056 | 1081 | { |
1057 | 1082 | return 0; |
1058 | 1083 | } |
1059 | 1084 | |
1060 | 1085 | |
1061 | 1086 | static int |
1062 | -freerunner_gps_inject_location(double latitude, double longitude, float accuracy) | |
1087 | +serial_gps_inject_location(double latitude, double longitude, float accuracy) | |
1063 | 1088 | { |
1064 | 1089 | return 0; |
1065 | 1090 | } |
1066 | 1091 | |
1067 | 1092 | static void |
1068 | -freerunner_gps_delete_aiding_data(GpsAidingData flags) | |
1093 | +serial_gps_delete_aiding_data(GpsAidingData flags) | |
1069 | 1094 | { |
1070 | 1095 | } |
1071 | 1096 | |
1072 | -static int freerunner_gps_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence, | |
1097 | +static int serial_gps_set_position_mode(GpsPositionMode mode, GpsPositionRecurrence recurrence, | |
1073 | 1098 | uint32_t min_interval, uint32_t preferred_accuracy, uint32_t preferred_time) |
1074 | 1099 | { |
1075 | 1100 | GpsState* s = _gps_state; |
1076 | 1101 | |
1077 | - // only standalone supported for now. | |
1078 | -// if (mode != GPS_POSITION_MODE_STANDALONE) | |
1079 | -// return -1; | |
1080 | - | |
1081 | 1102 | if (!s->init) { |
1082 | 1103 | D("%s: called with uninitialized state !!", __FUNCTION__); |
1083 | 1104 | return -1; |
@@ -1090,28 +1111,28 @@ static int freerunner_gps_set_position_mode(GpsPositionMode mode, GpsPositionRec | ||
1090 | 1111 | } |
1091 | 1112 | |
1092 | 1113 | static const void* |
1093 | -freerunner_gps_get_extension(const char* name) | |
1114 | +serial_gps_get_extension(const char* name) | |
1094 | 1115 | { |
1095 | 1116 | return NULL; |
1096 | 1117 | } |
1097 | 1118 | |
1098 | -static const GpsInterface freerunnerGpsInterface = { | |
1119 | +static const GpsInterface serialGpsInterface = { | |
1099 | 1120 | sizeof(GpsInterface), |
1100 | - freerunner_gps_init, | |
1101 | - freerunner_gps_start, | |
1102 | - freerunner_gps_stop, | |
1103 | - freerunner_gps_cleanup, | |
1104 | - freerunner_gps_inject_time, | |
1105 | - freerunner_gps_inject_location, | |
1106 | - freerunner_gps_delete_aiding_data, | |
1107 | - freerunner_gps_set_position_mode, | |
1108 | - freerunner_gps_get_extension, | |
1121 | + serial_gps_init, | |
1122 | + serial_gps_start, | |
1123 | + serial_gps_stop, | |
1124 | + serial_gps_cleanup, | |
1125 | + serial_gps_inject_time, | |
1126 | + serial_gps_inject_location, | |
1127 | + serial_gps_delete_aiding_data, | |
1128 | + serial_gps_set_position_mode, | |
1129 | + serial_gps_get_extension, | |
1109 | 1130 | }; |
1110 | 1131 | |
1111 | 1132 | const GpsInterface* gps_get_hardware_interface() |
1112 | 1133 | { |
1113 | 1134 | D("gps dev get_hardware_interface"); |
1114 | - return &freerunnerGpsInterface; | |
1135 | + return &serialGpsInterface; | |
1115 | 1136 | } |
1116 | 1137 | |
1117 | 1138 |
@@ -1237,9 +1258,8 @@ static void gps_dev_set_message_rate(int fd, int rate) | ||
1237 | 1258 | unsigned int i; |
1238 | 1259 | |
1239 | 1260 | char *msg[] = { |
1240 | - "GGA", "GLL", "ZDA", | |
1241 | - "VTG", "GSA", "GSV", | |
1242 | - "RMC" | |
1261 | + "GGA", "GLL", "VTG", | |
1262 | + "GSA", "GSV", "RMC" | |
1243 | 1263 | }; |
1244 | 1264 | |
1245 | 1265 | for (i = 0; i < sizeof(msg)/sizeof(msg[0]); ++i) { |
@@ -1308,7 +1328,7 @@ struct hw_module_t HAL_MODULE_INFO_SYM = { | ||
1308 | 1328 | .version_major = 1, |
1309 | 1329 | .version_minor = 0, |
1310 | 1330 | .id = GPS_HARDWARE_MODULE_ID, |
1311 | - .name = "USB GPS Module", | |
1331 | + .name = "Serial GPS Module", | |
1312 | 1332 | .author = "The Android-x86 Open Source Project", |
1313 | 1333 | .methods = &gps_module_methods, |
1314 | 1334 | }; |