• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/gps


Commit MetaInfo

Révision496ac76b24e0827aba0b352bb5ae831af312437e (tree)
l'heure2015-04-24 23:41:09
AuteurKeith Conger <keith.conger@gmai...>
CommiterChih-Wei Huang

Message de Log

Cleanup

Change Summary

Modification

--- a/gps.c
+++ b/gps.c
@@ -60,9 +60,6 @@ static int id_in_fixed[12];
6060 #define GPS_DEV_SLOW_UPDATE_RATE (10)
6161 #define GPS_DEV_HIGH_UPDATE_RATE (1)
6262
63-#define GPS_DEV_LOW_BAUD (B4800)
64-#define GPS_DEV_HIGH_BAUD (B115200)
65-
6663 static void gps_dev_init(int fd);
6764 static void gps_dev_deinit(int fd);
6865 static void gps_dev_start(int fd);
@@ -76,18 +73,20 @@ static void gps_dev_stop(int fd);
7673 /*****************************************************************/
7774 /*****************************************************************/
7875
76+#define MAX_NMEA_TOKENS 32
77+
7978 typedef struct {
8079 const char* p;
8180 const char* end;
8281 } Token;
8382
84-#define MAX_NMEA_TOKENS 32
8583
8684 typedef struct {
8785 int count;
8886 Token tokens[ MAX_NMEA_TOKENS ];
8987 } NmeaTokenizer;
9088
89+
9190 static int
9291 nmea_tokenizer_init( NmeaTokenizer* t, const char* p, const char* end )
9392 {
@@ -132,6 +131,7 @@ nmea_tokenizer_init( NmeaTokenizer* t, const char* p, const char* end )
132131 return count;
133132 }
134133
134+
135135 static Token
136136 nmea_tokenizer_get( NmeaTokenizer* t, int index )
137137 {
@@ -145,6 +145,7 @@ nmea_tokenizer_get( NmeaTokenizer* t, int index )
145145 return tok;
146146 }
147147
148+
148149 static int
149150 str2int( const char* p, const char* end )
150151 {
@@ -169,6 +170,7 @@ Fail:
169170 return -1;
170171 }
171172
173+
172174 static double
173175 str2float( const char* p, const char* end )
174176 {
@@ -183,6 +185,7 @@ str2float( const char* p, const char* end )
183185 return strtod( temp, NULL );
184186 }
185187
188+
186189 /*****************************************************************/
187190 /*****************************************************************/
188191 /***** *****/
@@ -206,6 +209,7 @@ typedef struct {
206209 char in[ NMEA_MAX_SIZE+1 ];
207210 } NmeaReader;
208211
212+
209213 void update_gps_status(GpsStatusValue val)
210214 {
211215 GpsState* state = _gps_state;
@@ -215,6 +219,7 @@ void update_gps_status(GpsStatusValue val)
215219 state->callbacks->status_cb(&state->status);
216220 }
217221
222+
218223 void update_gps_svstatus(GpsSvStatus *val)
219224 {
220225 GpsState* state = _gps_state;
@@ -223,6 +228,7 @@ void update_gps_svstatus(GpsSvStatus *val)
223228 state->callbacks->sv_status_cb(val);
224229 }
225230
231+
226232 void update_gps_location(GpsLocation *fix)
227233 {
228234 GpsState* state = _gps_state;
@@ -231,6 +237,7 @@ void update_gps_location(GpsLocation *fix)
231237 state->callbacks->location_cb(fix);
232238 }
233239
240+
234241 static void
235242 nmea_reader_update_utc_diff( NmeaReader* r )
236243 {
@@ -324,6 +331,7 @@ nmea_reader_update_time( NmeaReader* r, Token tok )
324331 return 0;
325332 }
326333
334+
327335 static int
328336 nmea_reader_update_date( NmeaReader* r, Token date, Token time )
329337 {
@@ -331,7 +339,7 @@ nmea_reader_update_date( NmeaReader* r, Token date, Token time )
331339 int day, mon, year;
332340
333341 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);
335343 return -1;
336344 }
337345 day = str2int(tok.p, tok.p+2);
@@ -339,7 +347,7 @@ nmea_reader_update_date( NmeaReader* r, Token date, Token time )
339347 year = str2int(tok.p+4, tok.p+6) + 2000;
340348
341349 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);
343351 return -1;
344352 }
345353
@@ -374,7 +382,7 @@ nmea_reader_update_latlong( NmeaReader* r,
374382
375383 tok = latitude;
376384 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);
378386 return -1;
379387 }
380388 lat = convert_from_hhmm(tok);
@@ -383,7 +391,7 @@ nmea_reader_update_latlong( NmeaReader* r,
383391
384392 tok = longitude;
385393 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);
387395 return -1;
388396 }
389397 lon = convert_from_hhmm(tok);
@@ -464,10 +472,12 @@ nmea_reader_update_speed( NmeaReader* r,
464472 return 0;
465473 }
466474
475+
467476 static int
468477 nmea_reader_update_svs( NmeaReader* r, int inview, int num, int i, Token prn, Token elevation, Token azimuth, Token snr )
469478 {
470479 int o;
480+ int prnid;
471481 i = (num - 1)*4 + i;
472482 if (i < inview) {
473483 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
476486 r->sv_status.sv_list[i].snr=str2int(snr.p,snr.end);
477487 for (o=0;o<12;o++){
478488 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));
482491 }
483492 }
484493 }
@@ -520,7 +529,7 @@ nmea_reader_parse( NmeaReader* r )
520529
521530 tok = nmea_tokenizer_get(tzer, 0);
522531 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);
524533 return;
525534 }
526535 // ignore first two characters.
@@ -546,8 +555,7 @@ nmea_reader_parse( NmeaReader* r )
546555 nmea_reader_update_accuracy(r, tok_accuracy);
547556
548557 } else if ( !memcmp(tok.p, "GSA", 3) ) {
549- //Satellites are handled by RPC-side code.
550- /*
558+ /*
551559 1 = Mode:
552560 M=Manual, forced to operate in 2D or 3D
553561 A=Automatic, 3D/2D
@@ -559,7 +567,7 @@ nmea_reader_parse( NmeaReader* r )
559567 15 = PDOP
560568 16 = HDOP
561569 17 = VDOP
562- */
570+ */
563571 Token tok_mode = nmea_tokenizer_get(tzer,1);
564572 Token tok_fix = nmea_tokenizer_get(tzer,2);
565573 Token tok_id = nmea_tokenizer_get(tzer,3);
@@ -574,7 +582,6 @@ nmea_reader_parse( NmeaReader* r )
574582 Token tok_id = nmea_tokenizer_get(tzer,3+i);
575583 if ( tok_id.end > tok_id.p ){
576584 id_in_fixed[i]=str2int(tok_id.p,tok_id.end);
577- D("id='%i' satellite='%i'",i, id_in_fixed[i]);
578585 D("Satellite used '%.*s'", tok_id.end-tok_id.p, tok_id.p);
579586 }
580587 }
@@ -664,10 +671,9 @@ nmea_reader_parse( NmeaReader* r )
664671 }
665672 } else {
666673 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);
668675 }
669676
670-
671677 #if GPS_DEBUG
672678 if (r->fix.flags) {
673679
@@ -676,7 +682,7 @@ nmea_reader_parse( NmeaReader* r )
676682 char* end = p + sizeof(temp);
677683 struct tm utc;
678684
679- p += snprintf( p, end-p, "sending fix" );
685+ p += snprintf( p, end-p, "Sending fix" );
680686 if (r->fix.flags & GPS_LOCATION_HAS_LAT_LONG) {
681687 p += snprintf(p, end-p, " lat=%g lon=%g", r->fix.latitude, r->fix.longitude);
682688 }
@@ -694,7 +700,7 @@ nmea_reader_parse( NmeaReader* r )
694700 }
695701 gmtime_r( (time_t*) &r->fix.timestamp, &utc );
696702 p += snprintf(p, end-p, " time=%s", asctime( &utc ) );
697- ALOGD("%s\n", temp);
703+ D("%s\n", temp);
698704 }
699705 #endif
700706 if (r->fix.flags & GPS_LOCATION_HAS_ACCURACY) {
@@ -702,7 +708,7 @@ nmea_reader_parse( NmeaReader* r )
702708 _gps_state->callbacks->location_cb( &r->fix );
703709 r->fix.flags = 0;
704710 } else {
705- D("no callback, keeping data until needed !");
711+ D("No callback, keeping data until needed !");
706712 }
707713 }
708714 }
@@ -747,6 +753,7 @@ enum {
747753 CMD_STOP = 2
748754 };
749755
756+
750757 static void
751758 gps_state_done( GpsState* s )
752759 {
@@ -826,6 +833,7 @@ epoll_deregister( int epoll_fd, int fd )
826833 return ret;
827834 }
828835
836+
829837 /* this is the main thread, it waits for commands from gps_state_start/stop and,
830838 * when started, messages from the QEMU GPS daemon. these are simple NMEA sentences
831839 * that must be parsed to be converted into GPS fixes sent to the framework
@@ -846,7 +854,7 @@ gps_state_thread( void* arg )
846854 epoll_register( epoll_fd, control_fd );
847855 epoll_register( epoll_fd, gps_fd );
848856
849- D("gps thread running");
857+ D("GPS thread running");
850858
851859 // now loop
852860 for (;;) {
@@ -870,26 +878,24 @@ gps_state_thread( void* arg )
870878 if (fd == control_fd) {
871879 char cmd = 255;
872880 int ret;
873- D("gps control fd event");
881+ D("GPS control fd event");
874882 do {
875883 ret = read( fd, &cmd, 1 );
876884 } while (ret < 0 && errno == EINTR);
877885
878886 if (cmd == CMD_QUIT) {
879- D("gps thread quitting on demand");
887+ D("GPS thread quitting on demand");
880888 return;
881889 } else if (cmd == CMD_START) {
882890 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);
884892 started = 1;
885- //nmea_reader_set_callback( reader, state->callbacks.location_cb );
886893 update_gps_status(GPS_STATUS_SESSION_BEGIN);
887894 }
888895 } else if (cmd == CMD_STOP) {
889896 if (started) {
890- D("gps thread stopping");
897+ D("GPS thread stopping");
891898 started = 0;
892- //nmea_reader_set_callback( reader, NULL );
893899 update_gps_status(GPS_STATUS_SESSION_END);
894900 }
895901 }
@@ -903,7 +909,7 @@ gps_state_thread( void* arg )
903909 if (errno == EINTR)
904910 continue;
905911 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));
907913 break;
908914 }
909915 for (nn = 0; nn < ret; nn++)
@@ -936,8 +942,7 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks )
936942 state->callbacks = callbacks;
937943 D("gps_state_init");
938944
939- // look for a kernel-provided device name
940-
945+ // Look for a kernel-provided device name
941946 if (property_get("ro.kernel.android.gps",prop,"") == 0) {
942947 D("no kernel-provided gps device name");
943948 return;
@@ -953,9 +958,9 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks )
953958 return;
954959 }
955960
956- D("gps will read from %s", device);
961+ D("GPS will read from %s", device);
957962
958- // disable echo on serial lines
963+ // Disable echo on serial lines
959964 if ( isatty( state->fd ) ) {
960965 struct termios ios;
961966 tcgetattr( state->fd, &ios );
@@ -963,28 +968,28 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks )
963968 ios.c_oflag &= (~ONLCR); /* Stop \n -> \r\n translation on output */
964969 ios.c_iflag &= (~(ICRNL | INLCR)); /* Stop \r -> \n & \n -> \r translation on input */
965970 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
967972 property_get("ro.kernel.android.gpsttybaud",baud,"9600");
968973 if (strcmp(baud, "4800") == 0) {
969- ALOGE("setting gps baud rate to 4800");
974+ ALOGE("Setting gps baud rate to 4800");
970975 ios.c_cflag = B4800 | CRTSCTS | CS8 | CLOCAL | CREAD;
971976 } else if (strcmp(baud, "9600") == 0) {
972- ALOGE("setting gps baud rate to 9600");
977+ ALOGE("Setting gps baud rate to 9600");
973978 ios.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
974979 } else if (strcmp(baud, "19200") == 0) {
975- ALOGE("setting gps baud rate to 19200");
980+ ALOGE("Setting gps baud rate to 19200");
976981 ios.c_cflag = B19200 | CRTSCTS | CS8 | CLOCAL | CREAD;
977982 } else if (strcmp(baud, "38400") == 0) {
978- ALOGE("setting gps baud rate to 38400");
983+ ALOGE("Setting gps baud rate to 38400");
979984 ios.c_cflag = B38400 | CRTSCTS | CS8 | CLOCAL | CREAD;
980985 } else if (strcmp(baud, "57600") == 0) {
981- ALOGE("setting gps baud rate to 57600");
986+ ALOGE("Setting gps baud rate to 57600");
982987 ios.c_cflag = B57600 | CRTSCTS | CS8 | CLOCAL | CREAD;
983988 } else if (strcmp(baud, "115200") == 0) {
984- ALOGE("setting gps baud rate to 115200");
989+ ALOGE("Setting gps baud rate to 115200");
985990 ios.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
986991 } else {
987- ALOGE("gps baud rate unknown: '%s'", baud);
992+ ALOGE("GPS baud rate unknown: '%s'", baud);
988993 return;
989994 }
990995
@@ -992,18 +997,18 @@ gps_state_init( GpsState* state, GpsCallbacks* callbacks )
992997 }
993998
994999 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));
9961001 goto Fail;
9971002 }
9981003
9991004 state->thread = callbacks->create_thread_cb( "gps_state_thread", gps_state_thread, state );
10001005
10011006 if ( !state->thread ) {
1002- ALOGE("could not create gps thread: %s", strerror(errno));
1007+ ALOGE("Could not create GPS thread: %s", strerror(errno));
10031008 goto Fail;
10041009 }
10051010
1006- D("gps state initialized");
1011+ D("GPS state initialized");
10071012
10081013 return;
10091014
@@ -1020,7 +1025,6 @@ Fail:
10201025 /*****************************************************************/
10211026 /*****************************************************************/
10221027
1023-
10241028 static int
10251029 serial_gps_init(GpsCallbacks* callbacks)
10261030 {
@@ -1036,6 +1040,7 @@ serial_gps_init(GpsCallbacks* callbacks)
10361040 return 0;
10371041 }
10381042
1043+
10391044 static void
10401045 serial_gps_cleanup(void)
10411046 {
@@ -1112,12 +1117,14 @@ static int serial_gps_set_position_mode(GpsPositionMode mode, GpsPositionRecurre
11121117 return 0;
11131118 }
11141119
1120+
11151121 static const void*
11161122 serial_gps_get_extension(const char* name)
11171123 {
11181124 return NULL;
11191125 }
11201126
1127+
11211128 static const GpsInterface serialGpsInterface = {
11221129 sizeof(GpsInterface),
11231130 serial_gps_init,
@@ -1131,14 +1138,14 @@ static const GpsInterface serialGpsInterface = {
11311138 serial_gps_get_extension,
11321139 };
11331140
1141+
11341142 const GpsInterface* gps_get_hardware_interface()
11351143 {
1136- D("gps dev get_hardware_interface");
1144+ D("GPS dev get_hardware_interface");
11371145 return &serialGpsInterface;
11381146 }
11391147
11401148
1141-
11421149 /*****************************************************************/
11431150 /*****************************************************************/
11441151 /***** *****/
@@ -1149,42 +1156,10 @@ const GpsInterface* gps_get_hardware_interface()
11491156
11501157 static void gps_dev_power(int state)
11511158 {
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
11851159 return;
11861160 }
11871161
1162+
11881163 static void gps_dev_send(int fd, char *msg)
11891164 {
11901165 int i, n, ret;
@@ -1206,6 +1181,7 @@ static void gps_dev_send(int fd, char *msg)
12061181 } while (n < i);
12071182 }
12081183
1184+
12091185 static unsigned char gps_dev_calc_nmea_csum(char *msg)
12101186 {
12111187 unsigned char csum = 0;
@@ -1218,6 +1194,7 @@ static unsigned char gps_dev_calc_nmea_csum(char *msg)
12181194 return csum;
12191195 }
12201196
1197+
12211198 static void gps_dev_set_nmea_message_rate(int fd, char *msg, int rate)
12221199 {
12231200 char buff[50];
@@ -1231,9 +1208,10 @@ static void gps_dev_set_nmea_message_rate(int fd, char *msg, int rate)
12311208
12321209 gps_dev_send(fd, buff);
12331210
1234- D("gps sent to device: %s", buff);
1211+ D("GPS sent to device: %s", buff);
12351212 }
12361213
1214+
12371215 static void gps_dev_set_baud_rate(int fd, int baud)
12381216 {
12391217 char buff[50];
@@ -1249,11 +1227,12 @@ static void gps_dev_set_baud_rate(int fd, int baud)
12491227
12501228 gps_dev_send(fd, buff);
12511229
1252- D("gps sent to device: %s", buff);
1230+ D("Sent to device: %s", buff);
12531231
12541232 }
12551233 }
12561234
1235+
12571236 static void gps_dev_set_message_rate(int fd, int rate)
12581237 {
12591238
@@ -1271,49 +1250,48 @@ static void gps_dev_set_message_rate(int fd, int rate)
12711250 return;
12721251 }
12731252
1253+
12741254 static void gps_dev_init(int fd)
12751255 {
12761256 gps_dev_power(1);
12771257
1278- //usleep(1000*1000);
1279-
1280- // To set to STOP state
1281- //gps_dev_stop(fd);
1282-
12831258 return;
12841259 }
12851260
1261+
12861262 static void gps_dev_deinit(int fd)
12871263 {
12881264 gps_dev_power(0);
12891265 }
12901266
1267+
12911268 static void gps_dev_start(int fd)
12921269 {
12931270 // Set full message rate
12941271 gps_dev_set_message_rate(fd, GPS_DEV_HIGH_UPDATE_RATE);
12951272
1296- D("gps dev start initiated");
1273+ D("GPS dev start initiated");
12971274 }
12981275
1276+
12991277 static void gps_dev_stop(int fd)
13001278 {
13011279 // Set slow message rate
13021280 gps_dev_set_message_rate(fd, GPS_DEV_SLOW_UPDATE_RATE);
13031281
1304- D("gps dev stop initiated");
1282+ D("GPS dev stop initiated");
13051283 }
13061284
1285+
13071286 static int open_gps(const struct hw_module_t* module, char const* name, struct hw_device_t** device)
13081287 {
1309- D("gps dev open_gps");
1288+ D("GPS dev open_gps");
13101289 struct gps_device_t *dev = malloc(sizeof(struct gps_device_t));
13111290 memset(dev, 0, sizeof(*dev));
13121291
13131292 dev->common.tag = HARDWARE_DEVICE_TAG;
13141293 dev->common.version = 0;
13151294 dev->common.module = (struct hw_module_t*)module;
1316- // dev->common.close = (int (*)(struct hw_device_t*))close_lights;
13171295 dev->get_gps_interface = gps_get_hardware_interface;
13181296
13191297 *device = &dev->common;
@@ -1325,6 +1303,7 @@ static struct hw_module_methods_t gps_module_methods = {
13251303 .open = open_gps
13261304 };
13271305
1306+
13281307 struct hw_module_t HAL_MODULE_INFO_SYM = {
13291308 .tag = HARDWARE_MODULE_TAG,
13301309 .version_major = 1,