Skip to content

Commit

Permalink
Add an end trip + force sync button
Browse files Browse the repository at this point in the history
To force the push of other entries (e.g. mode confirmation, incidents)
entered after a trip is complete. Normally, these would be pushed when the
next trip ends, but for development and debugging, it is useful to
be able to force the push of all entries.

Normally, we would do this by manually starting and ending a trip, but tis is
faster and does not rely on networking set up correctly on the emulator. The
android emulator, for example, has device-only networking turned on by
default.
  • Loading branch information
shankari committed Mar 29, 2019
1 parent a650db6 commit 29b3dba
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
62 changes: 57 additions & 5 deletions www/js/control/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ angular.module('emission.main.control',['emission.services',
$scope.$apply(function() {
$scope.settings.collect.state = response;
});
return response;
}, function(error) {
$ionicPopup.alert("while reading FSM state, "+error);
$ionicPopup.alert("while getting current state, "+error);
});
};

Expand Down Expand Up @@ -265,13 +266,39 @@ angular.module('emission.main.control',['emission.services',
}
};

var getStartTransitionKey = function() {
if($scope.isAndroid()) {
return "local.transition.exited_geofence";
}
else if($scope.isIOS()) {
return "T_EXITED_GEOFENCE";
}
}

var getEndTransitionKey = function() {
if($scope.isAndroid()) {
return "local.transition.stopped_moving";
}
else if($scope.isIOS()) {
return "T_TRIP_ENDED";
}
}

var getOngoingTransitionState = function() {
if($scope.isAndroid()) {
return "local.state.ongoing_trip";
}
else if($scope.isIOS()) {
return "STATE_ONGOING_TRIP";
}
}

$scope.forceSync = function() {
ClientStats.addEvent(ClientStats.getStatKeys().BUTTON_FORCE_SYNC).then(
function() {
console.log("Added "+ClientStats.getStatKeys().BUTTON_FORCE_SYNC+" event");
});
ControlSyncHelper.forceSync().then(function(response) {
Logger.log("response = "+response);
ControlSyncHelper.forceSync().then(function() {
/*
* Change to sensorKey to "background/location" after fixing issues
* with getLastSensorData and getLastMessages in the usercache
Expand All @@ -285,8 +312,7 @@ angular.module('emission.main.control',['emission.services',
// only have one entry for the battery, which is the one that was
// inserted on the last successful push.
var isTripEnd = function(entry) {
if (entry.metadata.key == "local.transition.stopped_moving" ||
entry.metadata.key == "T_TRIP_ENDED") {
if (entry.metadata.key == getEndTransition()) {
return true;
} else {
return false;
Expand Down Expand Up @@ -317,6 +343,32 @@ angular.module('emission.main.control',['emission.services',
});
};

var getTransition = function(transKey) {
var entry_data = {};
return $scope.getState().then(function(curr_state) {
entry_data.curr_state = curr_state;
if (transKey == getEndTransitionKey()) {
entry_data.curr_state = getOngoingTransitionState();
}
entry_data.transition = transKey;
entry_data.ts = moment().unix();
return entry_data;
})
}

$scope.endForceSync = function() {
/* First, quickly start and end the trip. Let's listen to the promise
* result for start so that we ensure ordering */
var sensorKey = "statemachine/transition";
return getTransition(getStartTransitionKey()).then(function(entry_data) {
return window.cordova.plugins.BEMUserCache.putMessage(sensorKey, entry_data);
}).then(function() {
return getTransition(getEndTransitionKey()).then(function(entry_data) {
return window.cordova.plugins.BEMUserCache.putMessage(sensorKey, entry_data);
})
}).then($scope.forceSync);
}

$scope.forceState = ControlCollectionHelper.forceState;
$scope.editCollectionConfig = ControlCollectionHelper.editConfig;
$scope.editSyncConfig = ControlSyncHelper.editConfig;
Expand Down
4 changes: 4 additions & 0 deletions www/templates/control/main-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<div class="control-list-text">Refresh</div>
<div ng-click="refreshScreen()" class="control-icon-button"><i class="ion-refresh"></i></div>
</div>
<div class="control-list-item">
<div class="control-list-text">End trip + sync</div>
<div ng-click="endForceSync()" class="control-icon-button" ><i class="ion-android-sync"></i></div>
</div>
<div class="control-list-item">
<div class="control-list-text">Check consent</div>
<div ng-click="checkConsent()" class="control-icon-button"><i class="ion-checkmark-circled"></i></div>
Expand Down

0 comments on commit 29b3dba

Please sign in to comment.