This section discusses about some Android OS specific GeoFence information.
Geofence applications are the ones in which you have a background location task running on the phone by which a flag will be raised when you move into or move out of a predefined area. This is useful for maintaining context awareness, social networks, mobile marketing, tracking, etc. BCM47521/BCM47531 has Geofence feature to minimize the power consumption of whole system. BCM47521/BCM47531 computes position with the on-chip processor. This allows the Host CPU to go to sleep for long periods of time, while Geofence areas are still monitored by the chipset BCM47521/BCM47531 wakes up the Host whenever a Geofence area is entered/exited. The Host in turn notifies the Application.
Here is the BCM47521 Geofence current measurement.
It tested with below setup.
Power Monitor was used to measure Geofence current.
This is what we measure.
The average current during host-offload searching(re-acquisition) and tracking is 24mA at chip level.
24mA at chip level is equivalent to 12mA at battery level.
Broadcom GPS library provides Geofence APIs to add and remove fence information. BCM47521 supports up to 64 Geofence requests simultaneously. Application can add set of a location and a radius to be monitored.
static GlRequest *MakeGeofenceReq( native_double dLatitude ,native_double dLongitude ,native_double dRadius ,GlReqOnStart cbOnStart ,GlReqOnGeofenceEvent cbOnEvent ,GlOnMemAlloc cbOnMemAlloc = GL_DFLT_MEM_ALLOC ,GlOnMemFree cbOnMemFree = GL_DFLT_MEM_FREE)
bool StartRequest(GlRequest *pReq)
bool StopRequest(GlRequest *pReq)
Broadcom GPS Library also provides a callback function to notify position and fence information when the monitored Geofence area is entered or exited.
void (*GlReqOnGeofenceEvent) (GlRequest *pReq, GL_REQ_GEOFENCE_CODE etCode, const GL_FIX_STATUS *pFixStatus)
Broadcom Geofence runs on the BCM47521 with host consuming very little power, and it does not need the host application processor.
Here is the state diagram to understand Geofence Behavior.
State Name | Descriptions |
---|---|
Host Position | If GPS system doesn't have enough aiding data for On Chip Position, it will run as Host Position state. When it has all aiding data, it will go to On Chip Position mode to save power. Whenever a new geofence is added, the state is changed to Host Position and do process to handle the geofence information, then it moves back to the previous state. |
House Keeping | Refresh aiding data for the ASIC and reprogram on-chip geofence parameters |
Report Geofence Transition or Geofence status | If geofence transition is happened, ASIC generates interrupt to wake up Host and proper Geofence event is sent to the application. And if the GPS system can't monitor geofences because of lack of reliability or unavailability of the GPS signal, it will report the status to application. After reporting it, it will go back to the previous state quickly. |
On Chip Position | ASIC runs without Host operation. ASIC calculates current position and geofence transitions. To go to On Chip Position, it needs valid position fix and 14 or more valid Ephemeris. |
Fence Far Away Mode | If stored geofences are far from current position, ASIC will be totally turned off. ASIC will wake up periodically to check the distance of geofences. The turn off period can be changed by the distance of geofences and user speed. |
Indoor Mode | If Indoor is detected, ASIC will be turned off to save power. ASIC will wake up periodically to do indoor detection. |
Here are general Android hardware interface layers.
Android provides "gps.h" and GpsLocationProvider.cpp as a JNI interface.
Since Android 4.3, it has been providing Geofence functions with Google Play Services.
You can implement Geofence feature with com.google.android.gms.location.LocationClient.
The LocationClient is the main entry point for location related APIs, such as location and geofence.
Use the locationClient to:
If you want to get more detail information, please see the Google developer page <http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html>
And also here is the example code <http://developer.android.com/training/location/geofencing.html#RequestGeofences>
Google Play Services is provided with binary, so we don't know the actual implementation of Geofence.
But we could deduce there might be a GMS.GeofenceHardwareService and GMS.GeofenceHardwareManager, so application can create and monitor hardware Geofence.
Here is the call flow for addGeofence() function.
We can zoom in the Frameworks part.
Android also provides APIs for Geofence. Application defines a Location and a radius to be monitored, and provides an intent (i.e. callback system) to be notified on entry/exit of a Geofence area.
Current LocationManager has functions for Geofence. But it uses Periodic GPS request instead of Hardware Geofence.
public void addProximityAlert (double latitude, double longitude, float radius, long expiration, PendingIntent intent)
public void removeProximityAlert (PendingIntent intent)
Here is the call flow of addProximityAlert.
To support Host offload Geofence, the host should provides
With on-Chip Geofencing of BCM47521, movement across a predefined boundary wakes the Host CPU from a power-saving sleep state.
BCM47521 has HOST_WAKE GPIO pin to wake host on Geofence event. Here is a hardware diagram to support Geofence.
BCM47521 enable the Host Application Processor to go to sleep for long periods of time, while Geofences are still monitored.
Whenever a Geofence is crossed, or when the chipset needs data from the Host, it will start the wake up process in order to have the Host CPU operations.
So there should be a connection to an interrupt on the Host CPU. The Host CPU should wake up and resume the HW flow control in a short time in order to get the serial communication ongoing.
Whenever BCM47521 needs to wake up the Host, it will take the following actions:
If BCM47521 doesn’t get any communication from the Host, it will have a few retries sending WakeUp packets. After some timeout, it will de-assert the WakeUp GPIO and resume normal processing.
HOST_WAKE is an output from 47521 that is used to wake up the Host AP.
Whenever the chipset is powered; HOST_WAKE defaults to high impedance pad (not driven) with internal pull-down. It can be connected directly to an IRQ input on the Host CPU.
When HOST_WAKE set, Kernel detects the rising edge of HOST_WAKE, and the Kernel won’t go sleep mode while HOST_WAKE is set (high).
The HOST_WAKE can be reset with two below conditions.
Note: GLL doesn’t check the HOST_WAKE GPIO status. Only Kernel checks the GPIO.
BCM47521 uses HW flow control to prevent data lost while the Host AP is asleep. Whenever the Host CPU goes to sleep, it needs to set the HW flow control lines to prevent data lost. BCM47521 Flow Control is active low and designated as nRTS and nCTS.
To wake up host, kernel needs a host_wake device driver.
The driver handles the HOST_WAKE interrupt from ASIC.
Broadcom provides the example of host_wake driver and it tested on Pandaboard.
The example code has
#include <linux/broadcom/bcm_gps_hostwake.h> //... // GPS Host Wake for Geofence #define GPS_HOSTWAKE_GPIO (139) static struct bcm_gps_hostwake_platform_data gps_hostwake_data = { .gpio_hostwake = GPS_HOSTWAKE_GPIO, }; static struct platform_device bcm_gps_hostwake = { .name = "bcm-gps-hostwake", .id = -1, .dev = { .platform_data = &gps_hostwake_data, }, }; static void __init board_init(void) { //... platform_device_register(&bcm_gps_hostwake); //...
There are following considerations in terms of setting up Host CPU when we implement Geofence wake up feature.
For host wake-up GPIO we need to make sure that this pin can be used as an external interrupt source.
For UART nRTS, as mentioned above, we need to make sure that nRTS pin must be asserted high before going into sleep and put to low after waking-up from sleep.
For nSTDBY GPIO, we need to make sure that it is asserted high even when Host CPU is in sleep state if gpsd is in Geofence mode because without nSTDBY being high ESW cannot run.
For external LNA power, we need to make it maintained even during AP sleep, because in Geofence mode, BCM47521 needs RF power for satellite signal acquisition. BCM47521 can enable LNA only when it is needed thru using LNA_EN pin.
So the radio of BCM47521 should be on during Host CPU sleep and LNA power should be alive during sleep.
Geofence can be tested with WinXP executable binary and Triggerfish EVK (that has BCM47521).
At first, configuration file should be changed to add new Geofence job with area information that will be monitored.
<job Id="geofence_test"> <task> <req_geofence FenceLatitude="33.75" FenceLongitude="-84.389" FenceRadius="100.0"/> <req_geofence FenceLatitude="33.75" FenceLongitude="-84.3833" FenceRadius="100.0"/> <req_geofence FenceLatitude="33.7454" FenceLongitude="-84.389" FenceRadius="100.0"/> <req_geofence FenceLatitude="33.7454" FenceLongitude="-84.3833" FenceRadius="100.0"/> </task> </job>
Please follow the below steps to run Geofence job on WinXP.
1. Open cmd to run 2. cd SDK_TOP_DIRECTORY 3. cd bin\WinXP 4. dir a. Make sure that you have glgps_win_xp.exe and gpsconfig.xml 5. glgps_win_xp.exe gpsconfig.xml geofence_test a. The job name is case sensitive 6. Observe the T/R LEDs blinking on the evaluation kit. 7. To quit, click on the cmd Window, press "q" on the keyboard. Ctrl-C won't work. 8. Search for PGLOR,2,GFC in the log file under log directory a. The log directory can be changed with LogDirectory in configuration file.
GPS log file contains internal GPS information and NMEA data as well. NMEA data shows Geofence information and event when Geofence is crossed.
$PGLOR,0,GFC - GeoFence Fix
$PGLOR,0,GFC,2,ddmmyy,hhmmss.ms,4.0,37.3,-121.4,400.0,event[,fixes,trials]*CC 1 2 3 4 5 6 7 8 9 10 11* 12* The fields are: - 1 - Sentence version [0] - 2 - Sentence identifier "GFC" - 3 - request ID - 4 - UTC day, month, year - 5 - UTC hours, minutes, seconds, 100ths of seconds - 6 - Time (seconds) since the request was received - 7,8 - Latitude, longitude of geofence (decimal degrees) - 9 - Radius of geofence (meters) - 10 - Event: - IN or OUT from geofence - ADD or DELETE geofence - YLD - 11 - Only for YLD event: number of fixes - 12 - Only for YLD event: number of trials - CC - checksum
Here are examples of Geofence NMEA.
Event | NMEA |
---|---|
Add Geofence | $PGLOR,1,NEW,GEOFENCE,0*1D $PGLOR,2,GFC,0,240413,022635.25,1.0,37.2006,127.0732,1000,ADD*72 |
Delete Geofence | $PGLOR,2,GFC,0,240413,030358.84,2244.6,37.2006,127.0732,1000,DELETE*1B $PGLOR,2,END,240413,030358.84,2244.6,GEOFENCE,0*1 |
In from Geofence | $PGLOR,2,GFC,10,240413,022639.32,5.0,37.4980,127.0277,500,IN*3A |
Out from Geofence | $PGLOR,2,GFC,10,240413,023110.09,277.7,37.4980,127.0277,500,OUT*76 |
Yield | $PGLOR,1,GFC,0,240413,023003.09,210.8,37.2006,127.0732,1000,YLD,3,3*67 |
Broadcom NMEA Log Analyzer can convert GPS log to kmz format, Geofence information can be shown graphically in Google Earth.
At first, convert GPS log file to NMEA file with bar2nmea.bat
bar2nmea.bat Broadcom GPS Log file can be dragged to this batch file for conversion. glgps_win_xp.exe for instance can produce some Broadcom GPS Log file. The output will be nmea file.
Then, convert the NMEA file to kmz to see in Google Earth.
nmea2kmz-g.bat Converts NMEA file to Google Earth KMZ file, with green positions without drawing estimated accuracy circles. (drag and drop of GLL or nmea file to the batch file is possible)
In Google Earth, green circle shows a Geofence that is defined in configuration file. And it shows IN/OUT events with time.