hardware/gps
Révision | 496ac76b24e0827aba0b352bb5ae831af312437e (tree) |
---|---|
l'heure | 2015-04-24 23:41:09 |
Auteur | Keith Conger <keith.conger@gmai...> |
Commiter | Chih-Wei Huang |
Cleanup
@@ -60,9 +60,6 @@ static int id_in_fixed[12]; | ||
60 | 60 | #define GPS_DEV_SLOW_UPDATE_RATE (10) |
61 | 61 | #define GPS_DEV_HIGH_UPDATE_RATE (1) |
62 | 62 | |
63 | -#define GPS_DEV_LOW_BAUD (B4800) | |
64 | -#define GPS_DEV_HIGH_BAUD (B115200) | |
65 | - | |
66 | 63 | static void gps_dev_init(int fd); |
67 | 64 | static void gps_dev_deinit(int fd); |
68 | 65 | static void gps_dev_start(int fd); |
@@ -76,18 +73,20 @@ static void gps_dev_stop(int fd); | ||
76 | 73 | /*****************************************************************/ |
77 | 74 | /*****************************************************************/ |
78 | 75 | |
76 | +#define MAX_NMEA_TOKENS 32 | |
77 | + | |
79 | 78 | typedef struct { |
80 | 79 | const char* p; |
81 | 80 | const char* end; |
82 | 81 | } Token; |
83 | 82 | |
84 | -#define MAX_NMEA_TOKENS 32 | |
85 | 83 | |
86 | 84 | typedef struct { |
87 | 85 | int count; |
88 | 86 | Token tokens[ MAX_NMEA_TOKENS ]; |
89 | 87 | } NmeaTokenizer; |
90 | 88 | |
89 | + | |
91 | 90 | static int |
92 | 91 | nmea_tokenizer_init( NmeaTokenizer* t, const char* p, const char* end ) |
93 | 92 | { |
@@ -132,6 +131,7 @@ nmea_tokenizer_init( NmeaTokenizer* t, const char* p, const char* end ) | ||
132 | 131 | return count; |
133 | 132 | } |
134 | 133 | |
134 | + | |
135 | 135 | static Token |
136 | 136 | nmea_tokenizer_get( NmeaTokenizer* t, int index ) |
137 | 137 | { |
@@ -145,6 +145,7 @@ nmea_tokenizer_get( NmeaTokenizer* t, int index ) | ||
145 | 145 | return tok; |
146 | 146 | } |
147 | 147 | |
148 | + | |
148 | 149 | static int |
149 | 150 | str2int( const char* p, const char* end ) |
150 | 151 | { |
@@ -169,6 +170,7 @@ Fail: | ||
169 | 170 | return -1; |
170 | 171 | } |
171 | 172 | |
173 | + | |
172 | 174 | static double |
173 | 175 | str2float( const char* p, const char* end ) |
174 | 176 | { |
@@ -183,6 +185,7 @@ str2float( const char* p, const char* end ) | ||
183 | 185 | return strtod( temp, NULL ); |
184 | 186 | } |
185 | 187 | |
188 | + | |
186 | 189 | /*****************************************************************/ |
187 | 190 | /*****************************************************************/ |
188 | 191 | /***** *****/ |
@@ -206,6 +209,7 @@ typedef struct { | ||
206 | 209 | char in[ NMEA_MAX_SIZE+1 ]; |
207 | 210 | } NmeaReader; |
208 | 211 | |
212 | + | |
209 | 213 | void update_gps_status(GpsStatusValue val) |
210 | 214 | { |
211 | 215 | GpsState* state = _gps_state; |
@@ -215,6 +219,7 @@ void update_gps_status(GpsStatusValue val) | ||
215 | 219 | state->callbacks->status_cb(&state->status); |
216 | 220 | } |
217 | 221 | |
222 | + | |
218 | 223 | void update_gps_svstatus(GpsSvStatus *val) |
219 | 224 | { |
220 | 225 | GpsState* state = _gps_state; |
@@ -223,6 +228,7 @@ void update_gps_svstatus(GpsSvStatus *val) | ||
223 | 228 | state->callbacks->sv_status_cb(val); |
224 | 229 | } |
225 | 230 | |
231 | + | |
226 | 232 | void update_gps_location(GpsLocation *fix) |
227 | 233 | { |
228 | 234 | GpsState* state = _gps_state; |
@@ -231,6 +237,7 @@ void update_gps_location(GpsLocation *fix) | ||
231 | 237 | state->callbacks->location_cb(fix); |
232 | 238 | } |
233 | 239 | |
240 | + | |
234 | 241 | static void |
235 | 242 | nmea_reader_update_utc_diff( NmeaReader* r ) |
236 | 243 | { |
@@ -324,6 +331,7 @@ nmea_reader_update_time( NmeaReader* r, Token tok ) | ||
324 | 331 | return 0; |
325 | 332 | } |
326 | 333 | |
334 | + | |
327 | 335 | static int |
328 | 336 | nmea_reader_update_date( NmeaReader* r, Token date, Token time ) |
329 | 337 | { |
@@ -331,7 +339,7 @@ nmea_reader_update_date( NmeaReader* r, Token date, Token time ) | ||
331 | 339 | int day, mon, year; |
332 | 340 | |
333 | 341 | if (tok.p + 6 != tok.end) { |
334 | - D("date not properly formatted: '%.*s'", tok.end-tok.p, tok.p); | |
342 | + D("Date not properly formatted: '%.*s'", tok.end-tok.p, tok.p); | |
335 | 343 | return -1; |
336 | 344 | } |
337 | 345 | day = str2int(tok.p, tok.p+2); |
@@ -339,7 +347,7 @@ nmea_reader_update_date( NmeaReader* r, Token date, Token time ) | ||
339 | 347 | year = str2int(tok.p+4, tok.p+6) + 2000; |
340 | 348 | |
341 | 349 | if ((day|mon|year) < 0) { |
342 | - D("date not properly formatted: '%.*s'", tok.end-tok.p, tok.p); | |
350 | + D("Date not properly formatted: '%.*s'", tok.end-tok.p, tok.p); | |
343 | 351 | return -1; |
344 | 352 | } |
345 | 353 |
@@ -374,7 +382,7 @@ nmea_reader_update_latlong( NmeaReader* r, | ||
374 | 382 | |
375 | 383 | tok = latitude; |
376 | 384 | if (tok.p + 6 > tok.end) { |
377 | - D("latitude is too short: '%.*s'", tok.end-tok.p, tok.p); | |
385 | + D("Latitude is too short: '%.*s'", tok.end-tok.p, tok.p); | |
378 | 386 | return -1; |
379 | 387 | } |
380 | 388 | lat = convert_from_hhmm(tok); |
@@ -383,7 +391,7 @@ nmea_reader_update_latlong( NmeaReader* r, | ||
383 | 391 | |
384 | 392 | tok = longitude; |
385 | 393 | if (tok.p + 6 > tok.end) { |
386 | - D("longitude is too short: '%.*s'", tok.end-tok.p, tok.p); | |
394 | + D("Longitude is too short: '%.*s'", tok.end-tok.p, tok.p); | |
387 | 395 | return -1; |
388 | 396 | } |
389 | 397 | lon = convert_from_hhmm(tok); |
@@ -464,10 +472,12 @@ nmea_reader_update_speed( NmeaReader* r, | ||
464 | 472 | return 0; |
465 | 473 | } |
466 | 474 | |
475 | + | |
467 | 476 | static int |
468 | 477 | nmea_reader_update_svs( NmeaReader* r, int inview, int num, int i, Token prn, Token elevation, Token azimuth, Token snr ) |
469 | 478 | { |
470 | 479 | int o; |
480 | + int prnid; | |
471 | 481 | i = (num - 1)*4 + i; |
472 | 482 | if (i < inview) { |
473 | 483 | r->sv_status.sv_list[i].prn=str2int(prn.p,prn.end); |
@@ -476,9 +486,8 @@ nmea_reader_update_svs( NmeaReader* r, int inview, int num, int i, Token prn, T | ||
476 | 486 | r->sv_status.sv_list[i].snr=str2int(snr.p,snr.end); |
477 | 487 | for (o=0;o<12;o++){ |
478 | 488 | if (id_in_fixed[o]==str2int(prn.p,prn.end)){ |
479 | - int prni = str2int(prn.p, prn.end); | |
480 | - r->sv_status.used_in_fix_mask |= (1ul << (prni-1)); | |
481 | - D("sv_status.used_in_fix_mask: '%i'", r->sv_status.used_in_fix_mask); | |
489 | + prnid = str2int(prn.p, prn.end); | |
490 | + r->sv_status.used_in_fix_mask |= (1ul << (prnid-1)); | |
482 | 491 | } |
483 | 492 | } |
484 | 493 | } |
@@ -520,7 +529,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
520 | 529 | |
521 | 530 | tok = nmea_tokenizer_get(tzer, 0); |
522 | 531 | if (tok.p + 5 > tok.end) { |
523 | - D("sentence id '%.*s' too short, ignored.", tok.end-tok.p, tok.p); | |
532 | + D("Sentence id '%.*s' too short, ignored.", tok.end-tok.p, tok.p); | |
524 | 533 | return; |
525 | 534 | } |
526 | 535 | // ignore first two characters. |
@@ -546,8 +555,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
546 | 555 | nmea_reader_update_accuracy(r, tok_accuracy); |
547 | 556 | |
548 | 557 | } else if ( !memcmp(tok.p, "GSA", 3) ) { |
549 | - //Satellites are handled by RPC-side code. | |
550 | - /* | |
558 | + /* | |
551 | 559 | 1 = Mode: |
552 | 560 | M=Manual, forced to operate in 2D or 3D |
553 | 561 | A=Automatic, 3D/2D |
@@ -559,7 +567,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
559 | 567 | 15 = PDOP |
560 | 568 | 16 = HDOP |
561 | 569 | 17 = VDOP |
562 | - */ | |
570 | + */ | |
563 | 571 | Token tok_mode = nmea_tokenizer_get(tzer,1); |
564 | 572 | Token tok_fix = nmea_tokenizer_get(tzer,2); |
565 | 573 | Token tok_id = nmea_tokenizer_get(tzer,3); |
@@ -574,7 +582,6 @@ nmea_reader_parse( NmeaReader* r ) | ||
574 | 582 | Token tok_id = nmea_tokenizer_get(tzer,3+i); |
575 | 583 | if ( tok_id.end > tok_id.p ){ |
576 | 584 | id_in_fixed[i]=str2int(tok_id.p,tok_id.end); |
577 | - D("id='%i' satellite='%i'",i, id_in_fixed[i]); | |
578 | 585 | D("Satellite used '%.*s'", tok_id.end-tok_id.p, tok_id.p); |
579 | 586 | } |
580 | 587 | } |
@@ -664,10 +671,9 @@ nmea_reader_parse( NmeaReader* r ) | ||
664 | 671 | } |
665 | 672 | } else { |
666 | 673 | tok.p -= 2; |
667 | - D("unknown sentence '%.*s", tok.end-tok.p, tok.p); | |
674 | + D("Unknown sentence '%.*s", tok.end-tok.p, tok.p); | |
668 | 675 | } |
669 | 676 | |
670 | - | |
671 | 677 | #if GPS_DEBUG |
672 | 678 | if (r->fix.flags) { |
673 | 679 |
@@ -676,7 +682,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
676 | 682 | char* end = p + sizeof(temp); |
677 | 683 | struct tm utc; |
678 | 684 | |
679 | - p += snprintf( p, end-p, "sending fix" ); | |
685 | + p += snprintf( p, end-p, "Sending fix" ); | |
680 | 686 | if (r->fix.flags & GPS_LOCATION_HAS_LAT_LONG) { |
681 | 687 | p += snprintf(p, end-p, " lat=%g lon=%g", r->fix.latitude, r->fix.longitude); |
682 | 688 | } |
@@ -694,7 +700,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
694 | 700 | } |
695 | 701 | gmtime_r( (time_t*) &r->fix.timestamp, &utc ); |
696 | 702 | p += snprintf(p, end-p, " time=%s", asctime( &utc ) ); |
697 | - ALOGD("%s\n", temp); | |
703 | + D("%s\n", temp); | |
698 | 704 | } |
699 | 705 | #endif |
700 | 706 | if (r->fix.flags & GPS_LOCATION_HAS_ACCURACY) { |
@@ -702,7 +708,7 @@ nmea_reader_parse( NmeaReader* r ) | ||
702 | 708 | _gps_state->callbacks->location_cb( &r->fix ); |
703 | 709 | r->fix.flags = 0; |
704 | 710 | } else { |
705 | - D("no callback, keeping data until needed !"); | |
711 | + D("No callback, keeping data until needed !"); | |
706 | 712 | } |
707 | 713 | } |
708 | 714 | } |
@@ -747,6 +753,7 @@ enum { | ||
747 | 753 | CMD_STOP = 2 |
748 | 754 | }; |
749 | 755 | |
756 | + | |
750 | 757 | static void |
751 | 758 | gps_state_done( GpsState* s ) |
752 | 759 | { |
@@ -826,6 +833,7 @@ epoll_deregister( int epoll_fd, int fd ) | ||
826 | 833 | return ret; |
827 | 834 | } |
828 | 835 | |
836 | + | |
829 | 837 | /* this is the main thread, it waits for commands from gps_state_start/stop and, |
830 | 838 | * when started, messages from the QEMU GPS daemon. these are simple NMEA sentences |
831 | 839 | * that must be parsed to be converted into GPS fixes sent to the framework |
@@ -846,7 +854,7 @@ gps_state_thread( void* arg ) | ||
846 | 854 | epoll_register( epoll_fd, control_fd ); |
847 | 855 | epoll_register( epoll_fd, gps_fd ); |
848 | 856 | |
849 | - D("gps thread running"); | |
857 | + D("GPS thread running"); | |
850 | 858 | |
851 | 859 | // now loop |
852 | 860 | for (;;) { |
@@ -870,26 +878,24 @@ gps_state_thread( void* arg ) | ||
870 | 878 | if (fd == control_fd) { |
871 | 879 | char cmd = 255; |
872 | 880 | int ret; |
873 | - D("gps control fd event"); | |
881 | + D("GPS control fd event"); | |
874 | 882 | do { |
875 | 883 | ret = read( fd, &cmd, 1 ); |
876 | 884 | } while (ret < 0 && errno == EINTR); |
877 | 885 | |
878 | 886 | if (cmd == CMD_QUIT) { |
879 | - D("gps thread quitting on demand"); | |
887 | + D("GPS thread quitting on demand"); | |
880 | 888 | return; |
881 | 889 | } else if (cmd == CMD_START) { |
882 | 890 | if (!started) { |
883 | - D("gps thread starting location_cb=%p", state->callbacks->location_cb); | |
891 | + D("GPS thread starting location_cb=%p", state->callbacks->location_cb); | |
884 | 892 | started = 1; |
885 | - //nmea_reader_set_callback( reader, state->callbacks.location_cb ); | |
886 | 893 | update_gps_status(GPS_STATUS_SESSION_BEGIN); |
887 | 894 | } |
888 | 895 | } else if (cmd == CMD_STOP) { |
889 | 896 | if (started) { |
890 | - D("gps thread stopping"); | |
897 | + D("GPS thread stopping"); | |
891 | 898 | started = 0; |
892 | - //nmea_reader_set_callback( reader, NULL ); | |
893 | 899 | update_gps_status(GPS_STATUS_SESSION_END); |
894 | 900 | } |
895 | 901 | } |
@@ -903,7 +909,7 @@ gps_state_thread( void* arg ) | ||
903 | 909 | if (errno == EINTR) |
904 | 910 | continue; |
905 | 911 | if (errno != EWOULDBLOCK) |
906 | - ALOGE("error while reading from gps daemon socket: %s:", strerror(errno)); | |
912 | + ALOGE("Error while reading from GPS daemon socket: %s:", strerror(errno)); | |
907 | 913 | break; |
908 | 914 | } |
909 | 915 | for (nn = 0; nn < ret; nn++) |
@@ -936,8 +942,7 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
936 | 942 | state->callbacks = callbacks; |
937 | 943 | D("gps_state_init"); |
938 | 944 | |
939 | - // look for a kernel-provided device name | |
940 | - | |
945 | + // Look for a kernel-provided device name | |
941 | 946 | if (property_get("ro.kernel.android.gps",prop,"") == 0) { |
942 | 947 | D("no kernel-provided gps device name"); |
943 | 948 | return; |
@@ -953,9 +958,9 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
953 | 958 | return; |
954 | 959 | } |
955 | 960 | |
956 | - D("gps will read from %s", device); | |
961 | + D("GPS will read from %s", device); | |
957 | 962 | |
958 | - // disable echo on serial lines | |
963 | + // Disable echo on serial lines | |
959 | 964 | if ( isatty( state->fd ) ) { |
960 | 965 | struct termios ios; |
961 | 966 | tcgetattr( state->fd, &ios ); |
@@ -963,28 +968,28 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
963 | 968 | ios.c_oflag &= (~ONLCR); /* Stop \n -> \r\n translation on output */ |
964 | 969 | ios.c_iflag &= (~(ICRNL | INLCR)); /* Stop \r -> \n & \n -> \r translation on input */ |
965 | 970 | ios.c_iflag |= (IGNCR | IXOFF); /* Ignore \r & XON/XOFF on input */ |
966 | - // set baud rate and other flags | |
971 | + // Set baud rate and other flags | |
967 | 972 | property_get("ro.kernel.android.gpsttybaud",baud,"9600"); |
968 | 973 | if (strcmp(baud, "4800") == 0) { |
969 | - ALOGE("setting gps baud rate to 4800"); | |
974 | + ALOGE("Setting gps baud rate to 4800"); | |
970 | 975 | ios.c_cflag = B4800 | CRTSCTS | CS8 | CLOCAL | CREAD; |
971 | 976 | } else if (strcmp(baud, "9600") == 0) { |
972 | - ALOGE("setting gps baud rate to 9600"); | |
977 | + ALOGE("Setting gps baud rate to 9600"); | |
973 | 978 | ios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD; |
974 | 979 | } else if (strcmp(baud, "19200") == 0) { |
975 | - ALOGE("setting gps baud rate to 19200"); | |
980 | + ALOGE("Setting gps baud rate to 19200"); | |
976 | 981 | ios.c_cflag = B19200 | CRTSCTS | CS8 | CLOCAL | CREAD; |
977 | 982 | } else if (strcmp(baud, "38400") == 0) { |
978 | - ALOGE("setting gps baud rate to 38400"); | |
983 | + ALOGE("Setting gps baud rate to 38400"); | |
979 | 984 | ios.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD; |
980 | 985 | } else if (strcmp(baud, "57600") == 0) { |
981 | - ALOGE("setting gps baud rate to 57600"); | |
986 | + ALOGE("Setting gps baud rate to 57600"); | |
982 | 987 | ios.c_cflag = B57600 | CRTSCTS | CS8 | CLOCAL | CREAD; |
983 | 988 | } else if (strcmp(baud, "115200") == 0) { |
984 | - ALOGE("setting gps baud rate to 115200"); | |
989 | + ALOGE("Setting gps baud rate to 115200"); | |
985 | 990 | ios.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD; |
986 | 991 | } else { |
987 | - ALOGE("gps baud rate unknown: '%s'", baud); | |
992 | + ALOGE("GPS baud rate unknown: '%s'", baud); | |
988 | 993 | return; |
989 | 994 | } |
990 | 995 |
@@ -992,18 +997,18 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks ) | ||
992 | 997 | } |
993 | 998 | |
994 | 999 | if ( socketpair( AF_LOCAL, SOCK_STREAM, 0, state->control ) < 0 ) { |
995 | - ALOGE("could not create thread control socket pair: %s", strerror(errno)); | |
1000 | + ALOGE("Could not create thread control socket pair: %s", strerror(errno)); | |
996 | 1001 | goto Fail; |
997 | 1002 | } |
998 | 1003 | |
999 | 1004 | state->thread = callbacks->create_thread_cb( "gps_state_thread", gps_state_thread, state ); |
1000 | 1005 | |
1001 | 1006 | if ( !state->thread ) { |
1002 | - ALOGE("could not create gps thread: %s", strerror(errno)); | |
1007 | + ALOGE("Could not create GPS thread: %s", strerror(errno)); | |
1003 | 1008 | goto Fail; |
1004 | 1009 | } |
1005 | 1010 | |
1006 | - D("gps state initialized"); | |
1011 | + D("GPS state initialized"); | |
1007 | 1012 | |
1008 | 1013 | return; |
1009 | 1014 |
@@ -1020,7 +1025,6 @@ Fail: | ||
1020 | 1025 | /*****************************************************************/ |
1021 | 1026 | /*****************************************************************/ |
1022 | 1027 | |
1023 | - | |
1024 | 1028 | static int |
1025 | 1029 | serial_gps_init(GpsCallbacks* callbacks) |
1026 | 1030 | { |
@@ -1036,6 +1040,7 @@ serial_gps_init(GpsCallbacks* callbacks) | ||
1036 | 1040 | return 0; |
1037 | 1041 | } |
1038 | 1042 | |
1043 | + | |
1039 | 1044 | static void |
1040 | 1045 | serial_gps_cleanup(void) |
1041 | 1046 | { |
@@ -1112,12 +1117,14 @@ static int serial_gps_set_position_mode(GpsPositionMode mode, GpsPositionRecurre | ||
1112 | 1117 | return 0; |
1113 | 1118 | } |
1114 | 1119 | |
1120 | + | |
1115 | 1121 | static const void* |
1116 | 1122 | serial_gps_get_extension(const char* name) |
1117 | 1123 | { |
1118 | 1124 | return NULL; |
1119 | 1125 | } |
1120 | 1126 | |
1127 | + | |
1121 | 1128 | static const GpsInterface serialGpsInterface = { |
1122 | 1129 | sizeof(GpsInterface), |
1123 | 1130 | serial_gps_init, |
@@ -1131,14 +1138,14 @@ static const GpsInterface serialGpsInterface = { | ||
1131 | 1138 | serial_gps_get_extension, |
1132 | 1139 | }; |
1133 | 1140 | |
1141 | + | |
1134 | 1142 | const GpsInterface* gps_get_hardware_interface() |
1135 | 1143 | { |
1136 | - D("gps dev get_hardware_interface"); | |
1144 | + D("GPS dev get_hardware_interface"); | |
1137 | 1145 | return &serialGpsInterface; |
1138 | 1146 | } |
1139 | 1147 | |
1140 | 1148 | |
1141 | - | |
1142 | 1149 | /*****************************************************************/ |
1143 | 1150 | /*****************************************************************/ |
1144 | 1151 | /***** *****/ |
@@ -1149,42 +1156,10 @@ const GpsInterface* gps_get_hardware_interface() | ||
1149 | 1156 | |
1150 | 1157 | static void gps_dev_power(int state) |
1151 | 1158 | { |
1152 | - char prop[PROPERTY_VALUE_MAX]; | |
1153 | - int fd; | |
1154 | - char cmd = '0'; | |
1155 | - int ret; | |
1156 | -#if 0 | |
1157 | - if (property_get("gps.power_on",prop,GPS_POWER_IF) == 0) { | |
1158 | - ALOGE("no gps power interface name"); | |
1159 | - return; | |
1160 | - } | |
1161 | - | |
1162 | - do { | |
1163 | - fd = open( prop, O_RDWR ); | |
1164 | - } while (fd < 0 && errno == EINTR); | |
1165 | - | |
1166 | - if (fd < 0) { | |
1167 | - ALOGE("could not open gps power interfcae: %s", prop ); | |
1168 | - return; | |
1169 | - } | |
1170 | - | |
1171 | - if (state) { | |
1172 | - cmd = '1'; | |
1173 | - } else { | |
1174 | - cmd = '0'; | |
1175 | - } | |
1176 | - | |
1177 | - do { | |
1178 | - ret = write( fd, &cmd, 1 ); | |
1179 | - } while (ret < 0 && errno == EINTR); | |
1180 | - | |
1181 | - close(fd); | |
1182 | - | |
1183 | - DFR("gps power state = %c", cmd); | |
1184 | -#endif | |
1185 | 1159 | return; |
1186 | 1160 | } |
1187 | 1161 | |
1162 | + | |
1188 | 1163 | static void gps_dev_send(int fd, char *msg) |
1189 | 1164 | { |
1190 | 1165 | int i, n, ret; |
@@ -1206,6 +1181,7 @@ static void gps_dev_send(int fd, char *msg) | ||
1206 | 1181 | } while (n < i); |
1207 | 1182 | } |
1208 | 1183 | |
1184 | + | |
1209 | 1185 | static unsigned char gps_dev_calc_nmea_csum(char *msg) |
1210 | 1186 | { |
1211 | 1187 | unsigned char csum = 0; |
@@ -1218,6 +1194,7 @@ static unsigned char gps_dev_calc_nmea_csum(char *msg) | ||
1218 | 1194 | return csum; |
1219 | 1195 | } |
1220 | 1196 | |
1197 | + | |
1221 | 1198 | static void gps_dev_set_nmea_message_rate(int fd, char *msg, int rate) |
1222 | 1199 | { |
1223 | 1200 | char buff[50]; |
@@ -1231,9 +1208,10 @@ static void gps_dev_set_nmea_message_rate(int fd, char *msg, int rate) | ||
1231 | 1208 | |
1232 | 1209 | gps_dev_send(fd, buff); |
1233 | 1210 | |
1234 | - D("gps sent to device: %s", buff); | |
1211 | + D("GPS sent to device: %s", buff); | |
1235 | 1212 | } |
1236 | 1213 | |
1214 | + | |
1237 | 1215 | static void gps_dev_set_baud_rate(int fd, int baud) |
1238 | 1216 | { |
1239 | 1217 | char buff[50]; |
@@ -1249,11 +1227,12 @@ static void gps_dev_set_baud_rate(int fd, int baud) | ||
1249 | 1227 | |
1250 | 1228 | gps_dev_send(fd, buff); |
1251 | 1229 | |
1252 | - D("gps sent to device: %s", buff); | |
1230 | + D("Sent to device: %s", buff); | |
1253 | 1231 | |
1254 | 1232 | } |
1255 | 1233 | } |
1256 | 1234 | |
1235 | + | |
1257 | 1236 | static void gps_dev_set_message_rate(int fd, int rate) |
1258 | 1237 | { |
1259 | 1238 |
@@ -1271,49 +1250,48 @@ static void gps_dev_set_message_rate(int fd, int rate) | ||
1271 | 1250 | return; |
1272 | 1251 | } |
1273 | 1252 | |
1253 | + | |
1274 | 1254 | static void gps_dev_init(int fd) |
1275 | 1255 | { |
1276 | 1256 | gps_dev_power(1); |
1277 | 1257 | |
1278 | - //usleep(1000*1000); | |
1279 | - | |
1280 | - // To set to STOP state | |
1281 | - //gps_dev_stop(fd); | |
1282 | - | |
1283 | 1258 | return; |
1284 | 1259 | } |
1285 | 1260 | |
1261 | + | |
1286 | 1262 | static void gps_dev_deinit(int fd) |
1287 | 1263 | { |
1288 | 1264 | gps_dev_power(0); |
1289 | 1265 | } |
1290 | 1266 | |
1267 | + | |
1291 | 1268 | static void gps_dev_start(int fd) |
1292 | 1269 | { |
1293 | 1270 | // Set full message rate |
1294 | 1271 | gps_dev_set_message_rate(fd, GPS_DEV_HIGH_UPDATE_RATE); |
1295 | 1272 | |
1296 | - D("gps dev start initiated"); | |
1273 | + D("GPS dev start initiated"); | |
1297 | 1274 | } |
1298 | 1275 | |
1276 | + | |
1299 | 1277 | static void gps_dev_stop(int fd) |
1300 | 1278 | { |
1301 | 1279 | // Set slow message rate |
1302 | 1280 | gps_dev_set_message_rate(fd, GPS_DEV_SLOW_UPDATE_RATE); |
1303 | 1281 | |
1304 | - D("gps dev stop initiated"); | |
1282 | + D("GPS dev stop initiated"); | |
1305 | 1283 | } |
1306 | 1284 | |
1285 | + | |
1307 | 1286 | static int open_gps(const struct hw_module_t* module, char const* name, struct hw_device_t** device) |
1308 | 1287 | { |
1309 | - D("gps dev open_gps"); | |
1288 | + D("GPS dev open_gps"); | |
1310 | 1289 | struct gps_device_t *dev = malloc(sizeof(struct gps_device_t)); |
1311 | 1290 | memset(dev, 0, sizeof(*dev)); |
1312 | 1291 | |
1313 | 1292 | dev->common.tag = HARDWARE_DEVICE_TAG; |
1314 | 1293 | dev->common.version = 0; |
1315 | 1294 | dev->common.module = (struct hw_module_t*)module; |
1316 | - // dev->common.close = (int (*)(struct hw_device_t*))close_lights; | |
1317 | 1295 | dev->get_gps_interface = gps_get_hardware_interface; |
1318 | 1296 | |
1319 | 1297 | *device = &dev->common; |
@@ -1325,6 +1303,7 @@ static struct hw_module_methods_t gps_module_methods = { | ||
1325 | 1303 | .open = open_gps |
1326 | 1304 | }; |
1327 | 1305 | |
1306 | + | |
1328 | 1307 | struct hw_module_t HAL_MODULE_INFO_SYM = { |
1329 | 1308 | .tag = HARDWARE_MODULE_TAG, |
1330 | 1309 | .version_major = 1, |