|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#include "AccelerometerSampleService.h"
|
|
|
|
|
#include "MovesenseExerciseService.h"
|
|
|
|
|
#include "app-resources/resources.h"
|
|
|
|
|
#include "common/core/debug.h"
|
|
|
|
|
#include "meas_acc/resources.h"
|
|
|
|
@ -7,16 +7,16 @@
|
|
|
|
|
#include <float.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
const char* const AccelerometerSampleService::LAUNCHABLE_NAME = "SampleA";
|
|
|
|
|
const char* const MovesenseExerciseService::LAUNCHABLE_NAME = "SampleA";
|
|
|
|
|
#define SAMPLE_RATE 13
|
|
|
|
|
static const whiteboard::ExecutionContextId sExecutionContextId =
|
|
|
|
|
WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA::EXECUTION_CONTEXT;
|
|
|
|
|
WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::EXECUTION_CONTEXT;
|
|
|
|
|
|
|
|
|
|
static const whiteboard::LocalResourceId sProviderResources[] = {
|
|
|
|
|
WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA::LID,
|
|
|
|
|
WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::LID,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AccelerometerSampleService::AccelerometerSampleService()
|
|
|
|
|
MovesenseExerciseService::MovesenseExerciseService()
|
|
|
|
|
: ResourceClient(WBDEBUG_NAME(__FUNCTION__), sExecutionContextId),
|
|
|
|
|
ResourceProvider(WBDEBUG_NAME(__FUNCTION__), sExecutionContextId),
|
|
|
|
|
LaunchableModule(LAUNCHABLE_NAME, sExecutionContextId),
|
|
|
|
@ -24,11 +24,11 @@ AccelerometerSampleService::AccelerometerSampleService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AccelerometerSampleService::~AccelerometerSampleService()
|
|
|
|
|
MovesenseExerciseService::~MovesenseExerciseService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AccelerometerSampleService::initModule()
|
|
|
|
|
bool MovesenseExerciseService::initModule()
|
|
|
|
|
{
|
|
|
|
|
if (registerProviderResources(sProviderResources) != whiteboard::HTTP_CODE_OK)
|
|
|
|
|
{
|
|
|
|
@ -39,34 +39,34 @@ bool AccelerometerSampleService::initModule()
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::deinitModule()
|
|
|
|
|
void MovesenseExerciseService::deinitModule()
|
|
|
|
|
{
|
|
|
|
|
unregisterProviderResources(sProviderResources);
|
|
|
|
|
mModuleState = WB_RES::ModuleStateValues::UNINITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @see whiteboard::ILaunchableModule::startModule */
|
|
|
|
|
bool AccelerometerSampleService::startModule()
|
|
|
|
|
bool MovesenseExerciseService::startModule()
|
|
|
|
|
{
|
|
|
|
|
mModuleState = WB_RES::ModuleStateValues::STARTED;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onUnsubscribeResult(whiteboard::RequestId requestId,
|
|
|
|
|
void MovesenseExerciseService::onUnsubscribeResult(whiteboard::RequestId requestId,
|
|
|
|
|
whiteboard::ResourceId resourceId,
|
|
|
|
|
whiteboard::Result resultCode,
|
|
|
|
|
const whiteboard::Value& rResultData)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::onUnsubscribeResult() called.");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::onUnsubscribeResult() called.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onSubscribeResult(whiteboard::RequestId requestId,
|
|
|
|
|
void MovesenseExerciseService::onSubscribeResult(whiteboard::RequestId requestId,
|
|
|
|
|
whiteboard::ResourceId resourceId,
|
|
|
|
|
whiteboard::Result resultCode,
|
|
|
|
|
const whiteboard::Value& rResultData)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::onSubscribeResult() called. resourceId: %u, result: %d", resourceId.localResourceId, (uint32_t)resultCode);
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::onSubscribeResult() called. resourceId: %u, result: %d", resourceId.localResourceId, (uint32_t)resultCode);
|
|
|
|
|
|
|
|
|
|
whiteboard::Request relatedIncomingRequest;
|
|
|
|
|
bool relatedRequestFound = mOngoingRequests.get(requestId, relatedIncomingRequest);
|
|
|
|
@ -77,14 +77,14 @@ void AccelerometerSampleService::onSubscribeResult(whiteboard::RequestId request
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whiteboard::Result AccelerometerSampleService::startRunning(whiteboard::RequestId& remoteRequestId)
|
|
|
|
|
whiteboard::Result MovesenseExerciseService::startRunning(whiteboard::RequestId& remoteRequestId)
|
|
|
|
|
{
|
|
|
|
|
if (isRunning)
|
|
|
|
|
{
|
|
|
|
|
return whiteboard::HTTP_CODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::startRunning()");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::startRunning()");
|
|
|
|
|
|
|
|
|
|
// Reset max acceleration members
|
|
|
|
|
mMaxAccelerationSq = FLT_MIN;
|
|
|
|
@ -108,20 +108,20 @@ whiteboard::Result AccelerometerSampleService::startRunning(whiteboard::RequestI
|
|
|
|
|
return whiteboard::HTTP_CODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whiteboard::Result AccelerometerSampleService::stopRunning()
|
|
|
|
|
whiteboard::Result MovesenseExerciseService::stopRunning()
|
|
|
|
|
{
|
|
|
|
|
if (!isRunning)
|
|
|
|
|
{
|
|
|
|
|
return whiteboard::HTTP_CODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isResourceSubscribed(WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA::ID) == wb::HTTP_CODE_OK)
|
|
|
|
|
if (isResourceSubscribed(WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::ID) == wb::HTTP_CODE_OK)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::stopRunning() skipping. Subscribers still exist.");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::stopRunning() skipping. Subscribers still exist.");
|
|
|
|
|
return whiteboard::HTTP_CODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::stopRunning()");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::stopRunning()");
|
|
|
|
|
|
|
|
|
|
// Unsubscribe the LinearAcceleration resource, when unsubscribe is done, we get callback
|
|
|
|
|
wb::Result result = asyncUnsubscribe(mMeasAccResourceId, NULL);
|
|
|
|
@ -136,7 +136,7 @@ whiteboard::Result AccelerometerSampleService::stopRunning()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This callback is called when the resource we have subscribed notifies us
|
|
|
|
|
void AccelerometerSampleService::onNotify(whiteboard::ResourceId resourceId, const whiteboard::Value& value,
|
|
|
|
|
void MovesenseExerciseService::onNotify(whiteboard::ResourceId resourceId, const whiteboard::Value& value,
|
|
|
|
|
const whiteboard::ParameterList& parameters)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("onNotify() called.");
|
|
|
|
@ -185,7 +185,7 @@ void AccelerometerSampleService::onNotify(whiteboard::ResourceId resourceId, con
|
|
|
|
|
mMaxAccelerationSq = FLT_MIN;
|
|
|
|
|
|
|
|
|
|
// and update our WB resource. This causes notification to be fired to our subscribers
|
|
|
|
|
updateResource(WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA(),
|
|
|
|
|
updateResource(WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES(),
|
|
|
|
|
ResponseOptions::Empty, sampleDataValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -193,12 +193,12 @@ void AccelerometerSampleService::onNotify(whiteboard::ResourceId resourceId, con
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onSubscribe(const whiteboard::Request& request,
|
|
|
|
|
void MovesenseExerciseService::onSubscribe(const whiteboard::Request& request,
|
|
|
|
|
const whiteboard::ParameterList& parameters)
|
|
|
|
|
{
|
|
|
|
|
switch (request.getResourceConstId())
|
|
|
|
|
{
|
|
|
|
|
case WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA::ID:
|
|
|
|
|
case WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::ID:
|
|
|
|
|
{
|
|
|
|
|
// Someone subscribed to our service. Start collecting data and notifying when our service changes state (every 10 seconds)
|
|
|
|
|
whiteboard::RequestId remoteRequestId;
|
|
|
|
@ -223,12 +223,12 @@ void AccelerometerSampleService::onSubscribe(const whiteboard::Request& request,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onUnsubscribe(const whiteboard::Request& request,
|
|
|
|
|
void MovesenseExerciseService::onUnsubscribe(const whiteboard::Request& request,
|
|
|
|
|
const whiteboard::ParameterList& parameters)
|
|
|
|
|
{
|
|
|
|
|
switch (request.getResourceConstId())
|
|
|
|
|
{
|
|
|
|
|
case WB_RES::LOCAL::SAMPLE_ACCELEROMETER_DATA::ID:
|
|
|
|
|
case WB_RES::LOCAL::EXERCISE_SUMVECTOR_DENES::ID:
|
|
|
|
|
stopRunning();
|
|
|
|
|
returnResult(request, wb::HTTP_CODE_OK);
|
|
|
|
|
break;
|
|
|
|
@ -239,14 +239,14 @@ void AccelerometerSampleService::onUnsubscribe(const whiteboard::Request& reques
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onRemoteWhiteboardDisconnected(whiteboard::WhiteboardId whiteboardId)
|
|
|
|
|
void MovesenseExerciseService::onRemoteWhiteboardDisconnected(whiteboard::WhiteboardId whiteboardId)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::onRemoteWhiteboardDisconnected()");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::onRemoteWhiteboardDisconnected()");
|
|
|
|
|
stopRunning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AccelerometerSampleService::onClientUnavailable(whiteboard::ClientId clientId)
|
|
|
|
|
void MovesenseExerciseService::onClientUnavailable(whiteboard::ClientId clientId)
|
|
|
|
|
{
|
|
|
|
|
DEBUGLOG("AccelerometerSampleService::onClientUnavailable()");
|
|
|
|
|
DEBUGLOG("MovesenseExerciseService::onClientUnavailable()");
|
|
|
|
|
stopRunning();
|
|
|
|
|
}
|
|
|
|
|
}
|