Hi,

Subhash Chandra wrote:
Hi,

Sorry for the late reply been bit busy.


Subhash Chandra wrote:
Hi,

I don't have and AndNav installed, but if I remember AndNav
send the start Command. If
you start the engine you can stop the gps because you go in
navigation status, and the
event thread doesn't return.

while (mEnabled || mNavigating) {
              // this will wait for an event from the
GPS,
              // which will be reported via
reportLocation or reportStatus
              native_wait_for_event();
} and is
mNavigating = (status == GPS_STATUS_SESSION_BEGIN || status
== GPS_STATU
S_ENGINE_ON);

In the simulated version the ENGINE in not switch on.
Can you say the application?
ENGINE_ON has to be reported when GPS is enabled in the settings it tells that 
services that GPS is switched on, similarly ENGINE_OFF. You can stop reporting 
them as they part of the Java-Native Interface.

Coming to the code you are referring to in GpsLocationProvider.java

mNavigating = (status == GPS_STATUS_SESSION_BEGIN || status == 
GPS_STATUS_ENGINE_ON);

You should link with the logic below this line as well

if (wasNavigating != mNavigating) {

 638             synchronized(mListeners) {

 639                 int size = mListeners.size();

 640                 for (int i = 0; i < size; i++) {

 641                     Listener listener = mListeners.get(i);

 642                     try {

 643                         if (mNavigating) {

644 listener.mListener.onGpsStarted(); 645 } else {

646 listener.mListener.onGpsStopped(); 647 }

 648                     } catch (RemoteException e) {

 649                         Log.w(TAG, "RemoteException in reportStatus");

 650                         mListeners.remove(listener);

 651                         // adjust for size of list changing

 652                         size--;

 653                     }

 654                 }

 655             }

This logic looks pretty ok and event thread should exit when GPS is disabled. 
These are events reported to services from native code.

GPS Enbled in UI -> ENGINE_ON
APP uses the Location Provider -> SESSION_BEGIN
APP stops using location provider -> SESSION_END
GPS is disable in UI -> ENGINE_OFF
No engine does't go off. It call native_disable and post a message that change 
the
mEnabled, nothing arrive at the low level that change to ENGINE_OFF and the 
wait for
event thread to terminate. At the end if you swith on the engine you can't 
switch off.
So the logic is wrong or the code is wrong.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For my experience we do not write code in lower or for that matter any other 
layer based on code on other layer. It will be always based on the agreed 
interface between the interfaces. The agreed interface with GPS Location 
service with GPS driver is defined in gps.h of hardware project. According to 
this interface

- init
- start
- stop
- cleanup

are the control interfaces exposed from the driver. Following are status events 
sent to GPS service on these interface calls

- init (ENGINE_ON)
- start (SESSION_BEGIN)
- stop (SESSION_END)
- cleanup (ENGINE_OFF)

That is all a GPS driver can do and current GPS does it correctly. If some this 
is not happening in services properly we can not fix that in the driver, if we 
do so you are propagating the problems/bugs in services layer to driver layer 
saying they are fixes.

regards,
Subhash



      Download prohibited? No problem. CHAT from any browser, without download. 
Go to http://in.webmessenger.yahoo.com/


What do you think abuot these two?
These apply to the cupcake.


Michael
commit 38c70f1c725283300a195826515b820559c1e7b5
Author: Michael Trimarchi <[email protected]>
Date:   Mon Mar 9 00:40:36 2009 +0100

    Fix for gps, semplify the code and re-add ENGINE-ON and ENGINE-OFF. Move
    the fix on frameworks

Signed-off-by: Michael Trimarchi <[email protected]>

---
diff --git a/gps_freerunner.c b/gps_freerunner.c
index a31466a..c72498e 100644
--- a/gps_freerunner.c
+++ b/gps_freerunner.c
@@ -479,7 +479,7 @@ nmea_reader_parse( NmeaReader*  r )
     NmeaTokenizer  tzer[1];
     Token          tok;
 
-    DFR("Received: '%.*s'", r->pos, r->in);
+    D("Received: '%.*s'", r->pos, r->in);
 
     if (r->pos < 9) {
         D("Too short. discarded.");
@@ -570,7 +570,7 @@ nmea_reader_parse( NmeaReader*  r )
             if (prn > 0){
               r->sv_status.used_in_fix_mask |= (1ul << (32 - prn));
               r->sv_status_changed = 1;
-              DFR("%s: fix mask is %d", __FUNCTION__, r->sv_status.used_in_fix_mask);
+              D("%s: fix mask is %d", __FUNCTION__, r->sv_status.used_in_fix_mask);
             }
 
           }
@@ -624,7 +624,7 @@ nmea_reader_parse( NmeaReader*  r )
               r->sv_status_changed = 1;
           }
 
-          DFR("%s: GSV message with total satellites %d", __FUNCTION__, noSatellites);   
+          D("%s: GSV message with total satellites %d", __FUNCTION__, noSatellites);   
 
         }
 
@@ -918,7 +918,6 @@ gps_state_thread( void*  arg )
     D("gps thread running");
 
     gps_dev_init(gps_fd);
-
     GPS_STATUS_CB(state->callbacks, GPS_STATUS_ENGINE_ON); 
 
     // now loop
@@ -956,7 +955,7 @@ gps_state_thread( void*  arg )
                     }
                     else if (cmd == CMD_START) {
                         if (!started) {
-                            D("gps thread starting  location_cb=%p", state->callbacks.location_cb);
+                            DFR("gps thread starting  location_cb=%p", state->callbacks.location_cb);
                             started = 1;
 
                             gps_dev_start(gps_fd);
@@ -977,39 +976,29 @@ gps_state_thread( void*  arg )
                     else if (cmd == CMD_STOP) {
                         if (started) {
                             void *dummy;
-                            D("gps thread stopping");
+                            DFR("gps thread stopping");
                             started = 0;
 
                             gps_dev_stop(gps_fd);
 
                             state->init = STATE_INIT;
 
-                            pthread_join(state->tmr_thread, &dummy);
-
                             GPS_STATUS_CB(state->callbacks, GPS_STATUS_SESSION_END);
+                            pthread_join(state->tmr_thread, &dummy);
 
                         }
                     }
                 }
                 else if (fd == gps_fd)
                 {
-                    char  buff[32];
-                    D("gps fd event");
-                    for (;;) {
-                        int  nn, ret;
-
+                    char  buff[512];
+                    int  nn, ret;
+                    do {
                         ret = read( fd, buff, sizeof(buff) );
-                        if (ret < 0) {
-                            if (errno == EINTR)
-                                continue;
-                            if (errno != EWOULDBLOCK)
-                                LOGE("error while reading from gps daemon socket: %s:", strerror(errno));
-                            break;
-                        }
-                        D("received %d bytes: %.*s", ret, ret, buff);
+                    } while (ret < 0 && errno == EINTR);
+                    if (ret > 0)
                         for (nn = 0; nn < ret; nn++)
                             nmea_reader_addc( reader, buff[nn] );
-                    }
                     D("gps fd event end");
                 }
                 else
@@ -1021,9 +1010,8 @@ gps_state_thread( void*  arg )
     }
 Exit:
 
-    gps_dev_deinit(gps_fd);
-
     GPS_STATUS_CB(state->callbacks, GPS_STATUS_ENGINE_OFF);
+    gps_dev_deinit(gps_fd);
 
     return NULL;
 }
@@ -1033,37 +1021,18 @@ gps_timer_thread( void*  arg )
 {
 
   GpsState *state = (GpsState *)arg;
-  pthread_mutex_t timer_mtx;
-  pthread_cond_t  timer_cond;
-  struct timespec to;
 
   DFR("gps entered timer thread");
 
-  pthread_mutex_init(&timer_mtx, NULL);
-  pthread_cond_init(&timer_cond, NULL);
-
   do {
 
-    clock_gettime(CLOCK_MONOTONIC, &to);
-
-    if (state->fix_freq > 0) {
-      to.tv_sec += state->fix_freq;
-    } else {
-      to.tv_sec++;
-    }
-
-    pthread_mutex_lock(&timer_mtx);
-
-    // binoic specific function - non POSIX */
-    pthread_cond_timedwait_monotonic(&timer_cond, &timer_mtx, &to);
-
     DFR ("gps timer exp");
 
     GPS_STATE_LOCK_FIX(state);
 
     if (state->reader.fix.flags != 0) {
 
-      DFR("gps fix cb: 0x%x", state->reader.fix.flags);
+      D("gps fix cb: 0x%x", state->reader.fix.flags);
 
       if (state->callbacks.location_cb) {
           state->callbacks.location_cb( &state->reader.fix );
@@ -1079,7 +1048,7 @@ gps_timer_thread( void*  arg )
 
     if (state->reader.sv_status_changed != 0) {
 
-      DFR("gps sv status callback");
+      D("gps sv status callback");
 
       if (state->callbacks.sv_status_cb) {
           state->callbacks.sv_status_cb( &state->reader.sv_status );
@@ -1089,14 +1058,10 @@ gps_timer_thread( void*  arg )
     }
 
     GPS_STATE_UNLOCK_FIX(state);
-
-    pthread_mutex_unlock(&timer_mtx);
+    sleep(state->fix_freq);
 
   } while(state->init == STATE_START);
 
-  pthread_mutex_destroy(&timer_mtx);
-  pthread_cond_destroy(&timer_cond);
-
   DFR("gps timer thread destroyed");
 
   return NULL;
@@ -1169,7 +1134,7 @@ gps_state_init( GpsState*  state )
         goto Fail;
     }
 
-    DFR("gps state initialized");
+    D("gps state initialized");
 
     return;
 
@@ -1219,11 +1184,11 @@ freerunner_gps_start()
     GpsState*  s = _gps_state;
 
     if (!s->init) {
-        D("%s: called with uninitialized state !!", __FUNCTION__);
+        DFR("%s: called with uninitialized state !!", __FUNCTION__);
         return -1;
     }
 
-    DFR("%s: called", __FUNCTION__);
+    D("%s: called", __FUNCTION__);
     gps_state_start(s);
     return 0;
 }
@@ -1235,11 +1200,11 @@ freerunner_gps_stop()
     GpsState*  s = _gps_state;
 
     if (!s->init) {
-        D("%s: called with uninitialized state !!", __FUNCTION__);
+        DFR("%s: called with uninitialized state !!", __FUNCTION__);
         return -1;
     }
 
-    DFR("%s: called", __FUNCTION__);
+    D("%s: called", __FUNCTION__);
     gps_state_stop(s);
     return 0;
 }
@@ -1251,15 +1216,15 @@ freerunner_gps_set_fix_frequency(int freq)
     GpsState*  s = _gps_state;
 
     if (!s->init) {
-        D("%s: called with uninitialized state !!", __FUNCTION__);
+        DFR("%s: called with uninitialized state !!", __FUNCTION__);
         return;
     }
 
-    DFR("%s: called", __FUNCTION__);
+    D("%s: called", __FUNCTION__);
 
-    s->fix_freq = freq;
+    s->fix_freq = (freq <= 0) ? 1 : freq;
 
-    DFR("gps fix frquency set to %d secs", freq);
+    D("gps fix frquency set to %d secs", freq);
 }
 
 static int
@@ -1288,7 +1253,7 @@ static int freerunner_gps_set_position_mode(GpsPositionMode mode, int fix_freque
 
     s->fix_freq = fix_frequency;
 
-    DFR("gps fix frquency set to %d secs", fix_frequency);
+    D("gps fix frquency set to %d secs", fix_frequency);
 
     return 0;
 }
@@ -1413,7 +1378,7 @@ static void gps_dev_set_nmea_message_rate(int fd, char *msg, int rate)
 
   gps_dev_send(fd, buff);
 
-  DFR("gps sent to device: %s", buff);
+  D("gps sent to device: %s", buff);
 
   return;
 
@@ -1435,7 +1400,7 @@ static void gps_dev_set_baud_rate(int fd, int baud)
 
     gps_dev_send(fd, buff);
 
-    DFR("gps sent to device: %s", buff);
+    D("gps sent to device: %s", buff);
 
   }
 
@@ -1486,7 +1451,7 @@ static void gps_dev_start(int fd)
   // Set full message rate
   gps_dev_set_message_rate(fd, GPS_DEV_HIGH_UPDATE_RATE);
 
-  DFR("gps dev start initiated");
+  D("gps dev start initiated");
 
 }
 
@@ -1496,6 +1461,6 @@ static void gps_dev_stop(int fd)
   // Set slow message rate
   gps_dev_set_message_rate(fd, GPS_DEV_SLOW_UPDATE_RATE);
 
-  DFR("gps dev stop initiated");
+  D("gps dev stop initiated");
 
 }
commit 9c1320ba4e8826ad94c1f7706fc363c7a0788b78
Author: Michael Trimarchi <[email protected]>
Date:   Mon Mar 9 01:53:16 2009 +0100

    The mNavigation is on when the CMD_START command is send and so
    when the session BEGIN

Signed-off-by: Michael Trimarchi <[email protected]>
---

diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index c6f13c9..4532d0f 100644
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -644,7 +644,7 @@ public class GpsLocationProvider extends LocationProviderImpl {
         if (Config.LOGV) Log.v(TAG, "reportStatus status: " + status);
 
         boolean wasNavigating = mNavigating;
-        mNavigating = (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_ENGINE_ON);
+        mNavigating = (status == GPS_STATUS_SESSION_BEGIN);
 
         if (wasNavigating != mNavigating) {
             synchronized(mListeners) {
_______________________________________________
android-freerunner mailing list
[email protected]
http://android.koolu.org/listinfo.cgi/android-freerunner-koolu.org

Reply via email to