Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Fix to GNSS/Cell location APIs: don't call geofence callback if no lo…
Browse files Browse the repository at this point in the history
…cation is determined. (#1033)

GNSS and cellular do a test against a geofence in all cases, even if no location has been determined. The intention was that this would be signalled to the geofence callback by latitudeX1e9 and longitudeX1e9 being LLONG_MIN.  However, internally, what we have is both latitudeX1e7 and longitudex1e7 set to INT_MIN, and INT_MIN times 100 is not LLONG_MIN.  Since there is not a lot of point in testing an unknown position against a geofence, the GNSS and cellular code now doesn't bother doing the test (and therefore doesn't call the callback) if the latitude and longitude are unknown, which matches what the Wi-Fi location code was doing in any case.
  • Loading branch information
RobMeades authored Oct 30, 2023
1 parent 1f56324 commit e2600e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cell/src/u_cell_loc.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static void UULOC_urc_callback(uAtClientHandle_t atHandle, void *pParam)
break;
}

if (pUrcStorage->pFenceContext != NULL) {
if ((pUrcStorage->pFenceContext != NULL) && (pFixDataStorageBlock->errorCode == 0)) {
// Check out geofencing for this location, using the
// cached fence dynamic status, rather than the one we were
// passed, as it is solely this function that is keeping
Expand Down
18 changes: 2 additions & 16 deletions common/geofence/api/u_geofence.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,10 @@ typedef enum {
* and the result can be ignored.
* @param latitudeX1e9 the latitude of the position that
* caused the geofence event in
* degrees times ten to the power nine;
* LLONG_MIN is used to indicate a
* failed position fix, in which
* case the position state will
* remain unchanged from the previous
* call or will be
* #U_GEOFENCE_POSITION_STATE_NONE if
* the callback has never been called.
* degrees times ten to the power nine.
* @param longitudeX1e9 the longitude of the position that
* caused the geofence event in
* degrees times ten to the power nine;
* LLONG_MIN is used to indicate a
* failed position fix, in which
* case the position state will
* remain unchanged from the previous
* call or will be
* #U_GEOFENCE_POSITION_STATE_NONE if
* the callback has never been called.
* degrees times ten to the power nine.
* @param altitudeMillimetres the altitude of the position that
* caused the geofence event in
* millimetres; INT_MIN if only a 2D
Expand Down
3 changes: 1 addition & 2 deletions example/gnss/geofence_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ static void geofenceCallback(uDeviceHandle_t gnssHandle,
(void) distanceMillimetres;
(void) pCallbackParam;

if ((positionState != U_GEOFENCE_POSITION_STATE_NONE) &&
(latitudeX1e9 != LLONG_MIN) && (longitudeX1e9 != LLONG_MIN)) {
if (positionState != U_GEOFENCE_POSITION_STATE_NONE) {
prefix[0] = latLongToBits((int32_t) (longitudeX1e9 / 100), &(whole[0]), &(fraction[0]));
prefix[1] = latLongToBits((int32_t) (latitudeX1e9 / 100), &(whole[1]), &(fraction[1]));
uPortLog("https://maps.google.com/?q=%c%d.%07d,%c%d.%07d is %s \"%s\".\n",
Expand Down
52 changes: 28 additions & 24 deletions gnss/src/u_gnss_pos.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,20 @@ static void posGetTask(void *pParameter)
taskParameters.pCallback(taskParameters.gnssHandle, errorCode, latitudeX1e7,
longitudeX1e7, altitudeMillimetres, radiusMillimetres,
speedMillimetresPerSecond, svs, timeUtc);
// As well as the above, test the position against any
// fences associated with the instance, which may result
// in further callbacks being called and if GEODESIC is
// employed, may consume an additional ~5 kbytes of stack
uGeofenceContextTest(taskParameters.gnssHandle,
(uGeofenceContext_t *) taskParameters.pInstance->pFenceContext,
U_GEOFENCE_TEST_TYPE_NONE, false,
((int64_t) latitudeX1e7) * 100,
((int64_t) longitudeX1e7) * 100,
altitudeMillimetres,
radiusMillimetres,
altitudeUncertaintyMillimetres);
if (errorCode == 0) {
// As well as the above, test the position against any
// fences associated with the instance, which may result
// in further callbacks being called and if GEODESIC is
// employed, may consume an additional ~5 kbytes of stack
uGeofenceContextTest(taskParameters.gnssHandle,
(uGeofenceContext_t *) taskParameters.pInstance->pFenceContext,
U_GEOFENCE_TEST_TYPE_NONE, false,
((int64_t) latitudeX1e7) * 100,
((int64_t) longitudeX1e7) * 100,
altitudeMillimetres,
radiusMillimetres,
altitudeUncertaintyMillimetres);
}

U_PORT_MUTEX_UNLOCK(taskParameters.pInstance->posMutex);

Expand Down Expand Up @@ -399,18 +401,20 @@ static void messageCallback(uDeviceHandle_t gnssHandle,
speedMillimetresPerSecond,
svs,
timeUtc);
// As well as the above, test the position against any
// fences associated with the instance, which may result
// in further callbacks being called and if GEODESIC is
// employed, may consume an additional ~5 kbytes of stack
uGeofenceContextTest(gnssHandle,
(uGeofenceContext_t *) pInstance->pFenceContext,
U_GEOFENCE_TEST_TYPE_NONE, false,
((int64_t) latitudeX1e7) * 100,
((int64_t) longitudeX1e7) * 100,
altitudeMillimetres,
radiusMillimetres,
altitudeUncertaintyMillimetres);
if (errorCodeOrLength == 0) {
// As well as the above, test the position against any
// fences associated with the instance, which may result
// in further callbacks being called and if GEODESIC is
// employed, may consume an additional ~5 kbytes of stack
uGeofenceContextTest(gnssHandle,
(uGeofenceContext_t *) pInstance->pFenceContext,
U_GEOFENCE_TEST_TYPE_NONE, false,
((int64_t) latitudeX1e7) * 100,
((int64_t) longitudeX1e7) * 100,
altitudeMillimetres,
radiusMillimetres,
altitudeUncertaintyMillimetres);
}
}
}

Expand Down

0 comments on commit e2600e2

Please sign in to comment.