*/
static void pud_gateway_timer_callback(void *context __attribute__ ((unused))) {
union olsr_ip_addr bestGateway;
+ bool subStateExternalStateChange;
bool externalStateChange;
MovementState externalState;
TristateBoolean movingNow = TRISTATE_BOOLEAN_UNSET;
* State Determination
*/
- externalStateChange = determineStateWithHysteresis(SUBSTATE_GATEWAY, movingNow, &externalState);
+ determineStateWithHysteresis(SUBSTATE_GATEWAY, movingNow, &externalState, &externalStateChange,
+ &subStateExternalStateChange);
/*
* Update transmitGpsInformation
*/
- if ((externalState == MOVEMENT_STATE_MOVING) || externalStateChange) {
+ if ((externalState == MOVEMENT_STATE_MOVING) || subStateExternalStateChange) {
transmitGpsInformation.txGateway = bestGateway;
- transmitGpsInformation.updated = true;
}
(void) pthread_mutex_unlock(&transmitGpsInformation.mutex);
PositionUpdateEntry * incomingEntry;
PositionUpdateEntry * posAvgEntry;
MovementType movementResult;
- bool externalStateChange = false;
+ bool subStateExternalStateChange;
+ bool externalStateChange;
bool updateTransmitGpsInformation = false;
PositionUpdateEntry txPosition;
MovementState externalState;
* State Determination
*/
- externalStateChange = determineStateWithHysteresis(SUBSTATE_POSITION, movementResult.moving, &externalState);
+ determineStateWithHysteresis(SUBSTATE_POSITION, movementResult.moving, &externalState, &externalStateChange,
+ &subStateExternalStateChange);
/*
* Update transmitGpsInformation
*/
- updateTransmitGpsInformation = externalStateChange
+ updateTransmitGpsInformation = subStateExternalStateChange
|| (positionValid(posAvgEntry) && !positionValid(&txPosition))
|| (movementResult.inside == TRISTATE_BOOLEAN_SET);
* the movement result of the sub-state
* @param externalState
* a pointer to the variable in which to store the new external state
+ * @param externalStateChange
+ * a pointer to the variable in which to store whether the external state changed
+ * @param subStateExternalStateChange
+ * a pointer to the variable in which to store whether the sub-state external state changed
*/
-bool determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean movingNow,
- MovementState * externalState) {
+void determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean movingNow, MovementState * externalState,
+ bool * externalStateChange, bool * subStateExternalStateChange) {
MovementState newState;
bool internalStateChange;
- bool externalStateChange;
SubStateType * subState = &state.substate[subStateIndex];
(void) pthread_mutex_lock(&state.mutex);
}
}
- externalStateChange = (subState->externalState != newState);
+ *subStateExternalStateChange = (subState->externalState != newState);
subState->externalState = newState;
/*
* external state may transition into MOVING when either one of the sub-states say so (OR), and
* may transition into STATIONARY when all of the sub-states say so (AND)
*/
- if (externalStateChange) {
+ *externalStateChange = false;
+ if (*subStateExternalStateChange) {
bool transition;
if (newState == MOVEMENT_STATE_STATIONARY) {
}
if (transition) {
- externalStateChange = (state.externalState != newState);
+ *externalStateChange = (state.externalState != newState);
state.externalState = newState;
}
}
-
*externalState = state.externalState;
(void) pthread_mutex_unlock(&state.mutex);
-
- return externalStateChange;
}
MovementState getInternalState(SubStateIndex subStateIndex) {
void destroyState(void);
MovementState getExternalState(void);
MovementState getInternalState(SubStateIndex subStateIndex);
-bool determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean movingNow,
- MovementState * externalState);
+void determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean movingNow, MovementState * externalState,
+ bool * externalStateChange, bool * subStateExternalStateChange);
#endif /* _PUD_STATE_H_ */