#include "ordevice_template_device.h"
#define ORDEVICETEMPLATE__CLASS ORDEVICETEMPLATE__CLASSNAME
#define ORDEVICETEMPLATE__NAME ORDEVICETEMPLATE__CLASSSTR
#define ORDEVICETEMPLATE__LABEL "OR - Device Template"
#define ORDEVICETEMPLATE__DESC "OR - Device Template Description"
#define ORDEVICETEMPLATE__PREFIX "DeviceTemplate"
ORDEVICETEMPLATE__CLASS,
ORDEVICETEMPLATE__LABEL,
ORDEVICETEMPLATE__DESC,
bool ORDevice_Template::FBCreate()
{
mHardware.SetParent( this );
ModelTemplate.Children.Add(mTemplateRoot);
mTemplateRoot->Children.Add(mTemplateMarker);
mTemplateMarker->Bindings.Add( mNodeMarker_InR );
mTemplateMarker->Bindings.Add( mNodeMarker_InT );
FBTime lPeriod;
lPeriod.SetSecondDouble(1.0/60.0);
SamplingPeriod = lPeriod;
mSetCandidate = false;
return true;
}
void ORDevice_Template::FBDestroy()
{
}
bool ORDevice_Template::DeviceOperation( kDeviceOperations pOperation )
{
switch (pOperation)
{
case kOpInit: return Init();
case kOpStart: return Start();
case kOpStop: return Stop();
case kOpReset: return Reset();
case kOpDone: return Done();
}
return FBDevice::DeviceOperation( pOperation );
}
bool ORDevice_Template::Init()
{
FBProgress lProgress;
lProgress.Caption = "Device Template";
lProgress.Text = "Initializing device...";
return true;
}
bool ORDevice_Template::Start()
{
FBProgress lProgress;
lProgress.Caption = "Starting up device";
lProgress.Text = "Opening device communications";
Status = "Opening device communications";
if(!mHardware.Open())
{
Status = "Could not open device";
return false;
}
lProgress.Text = "Device found, getting setup information";
Status = "Getting setup information";
if(!mHardware.GetSetupInfo())
{
Status = "Could not get setup information from device.";
return false;
}
else
{
HardwareVersionInfo = "Device Template, v1.0";
Information = "";
}
if( mHardware.GetStreaming() )
{
lProgress.Text = "Sending START STREAM command";
Status = "Starting device streaming";
if(!mHardware.StartStream())
{
Status = "Could not start stream mode";
return false;
}
}
Status = "Ok";
return true;
}
bool ORDevice_Template::Stop()
{
FBProgress lProgress;
lProgress.Caption = "Shutting down device";
if( mHardware.GetStreaming() )
{
lProgress.Text = "Sending STOP STREAM command";
Status = "Stopping device streaming";
if(!mHardware.StopStream())
{
Status = "Could not stop streaming";
return false;
}
}
lProgress.Text = "Stopping device communications";
Status = "Stopping device communications";
if(!mHardware.Close())
{
Status = "Could not close device";
return false;
}
Status = "?";
return false;
}
bool ORDevice_Template::Done()
{
return false;
}
bool ORDevice_Template::Reset()
{
Stop();
return Start();
}
bool ORDevice_Template::AnimationNodeNotify(FBAnimationNode* pAnimationNode ,FBEvaluateInfo* pEvaluateInfo)
{
double lPos[3];
double lRot[3];
mHardware.GetPosition( lPos );
mHardware.GetRotation( lRot );
mNodeMarker_InT->WriteData( lPos, pEvaluateInfo );
mNodeMarker_InR->WriteData( lRot, pEvaluateInfo );
return true;
}
bool ORDevice_Template::DeviceEvaluationNotify( kTransportMode pMode, FBEvaluateInfo* pEvaluateInfo )
{
return true;
}
void ORDevice_Template::DeviceIONotify( kDeviceIOs pAction,FBDeviceNotifyInfo &pDeviceNotifyInfo)
{
int lNumberOfPackets;
FBTime lPacketTimeCode;
switch (pAction)
{
case kIOPlayModeWrite:
case kIOStopModeWrite:
{
}
break;
case kIOStopModeRead:
case kIOPlayModeRead:
{
lNumberOfPackets = mHardware.FetchData();
for( i=0; i<lNumberOfPackets; i++ )
{
DeviceRecordFrame ( pDeviceNotifyInfo );
AckOneSampleReceived( );
}
if( !mHardware.GetStreaming() )
{
mHardware.PollData();
}
break;
}
}
}
void ORDevice_Template::DeviceRecordFrame( FBDeviceNotifyInfo &pDeviceNotifyInfo )
{
FBAnimationNode* lDataT =
NULL;
FBAnimationNode* lDataR =
NULL;
double lPos[3];
double lRot[3];
FBTime lTime;
lTime = pDeviceNotifyInfo.GetLocalTime();
lDataT = mNodeMarker_InT->GetAnimationToRecord();
if (lDataT)
{
{
mHardware.GetPosition( lPos );
switch( SamplingMode )
{
{
lDataT->KeyAdd(lTime, lPos);
}
break;
{
lDataT->KeyAdd(lPos);
}
break;
}
}
}
lDataR = mNodeMarker_InR->GetAnimationToRecord();
if (lDataR)
{
{
mHardware.GetRotation( lRot );
switch( SamplingMode )
{
{
lDataR->KeyAdd(lTime, lRot);
}
break;
{
lDataR->KeyAdd(lRot);
}
break;
}
}
}
}
void ORDevice_Template::SetCandidates()
{
double lPos[3];
double lRot[3];
mHardware.GetPosition( lPos );
mHardware.GetRotation( lRot );
mNodeMarker_InT->SetCandidate( lPos );
mNodeMarker_InR->SetCandidate( lRot );
}
#define FBX_VERSION_TAG "Version"
#define FBX_VERSION_VAL 100
#define FBX_COMMPARAM_TAG "Communication"
bool ORDevice_Template::FbxStore(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
{
pFbxObject->FieldWriteI (FBX_VERSION_TAG,FBX_VERSION_VAL);
pFbxObject->FieldWriteBegin (FBX_COMMPARAM_TAG);
{
}
pFbxObject->FieldWriteEnd();
}
return true;
}
bool ORDevice_Template::FbxRetrieve(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
int Version;
if (pStoreWhat & kAttributes)
{
Version = pFbxObject->FieldReadI(FBX_VERSION_TAG);
if (pFbxObject->FieldReadBegin(FBX_COMMPARAM_TAG))
{
pFbxObject->FieldReadEnd();
}
}
return true;
}