devices/deviceoutput/ordeviceoutput_hardware.cxx

devices/deviceoutput/ordeviceoutput_hardware.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ordeviceoutput_hardware.h"
/************************************************
* Constructor.
************************************************/
ORDeviceOutputHardware::ORDeviceOutputHardware()
{
mExportFile = NULL;
mCounter = 0;
mSerialPort = 1;
mFileOpen = false;
mExportFilename = "C:\\ordeviceoutput.txt";
}
/************************************************
* Destructor.
************************************************/
ORDeviceOutputHardware::~ORDeviceOutputHardware()
{
}
/************************************************
* Open device communications.
************************************************/
bool ORDeviceOutputHardware::Open()
{
// TODO: Open serial port to hardware
mExportFile = fopen( mExportFilename, "wt" );
if( mExportFile )
{
mFileOpen = true;
}
return true;
}
/************************************************
* Get device setup information.
************************************************/
bool ORDeviceOutputHardware::GetSetupInfo()
{
// TODO: Get hardware information
return true;
}
/************************************************
* Close device communications.
************************************************/
bool ORDeviceOutputHardware::Close()
{
// TODO: Close network connection to server
if( mFileOpen )
{
fclose( mExportFile );
mFileOpen = false;
}
return true;
}
/************************************************
* Fetch a data packet from the device.
************************************************/
bool ORDeviceOutputHardware::FetchDataPacket(FBTime &pTime)
{
//Returns true if a new data packet is ready
// TODO: insert time stamp from data packet
pTime = mSystem.SystemTime;
// TODO: Replace this bogus code with real NON-BLOCKING TCP, UDP or serial calls
// to your data server.
PollData();
// As soon as enough bytes have been read to have data for all makers,
// return immediately, even if another data packer is waiting
// This function is nested in a while loop and will be called immediately
// as soon as the current data frame is processed.
// TODO: mCounter is a bogus variable there to simulate a time-reference
if(mCounter%4)
{
return true; // data for all elements of mChannelData[] has been found.
}
else
{
return false; // incomplete data packet has been read.
}
}
/************************************************
* Poll device.
* Device should get itself to send more data.
************************************************/
bool ORDeviceOutputHardware::PollData()
{
mCounter++;
return true;
}
/************************************************
* Send a data packet over the network to move lights.
************************************************/
bool ORDeviceOutputHardware::SendDataPacket(FBTime &pTime)
{
// Send to hardware
// High priority IO thread, must have minimal CPU usage.
// Non-blocking IO, send data to hardware via comm port, network, etc.
if( mFileOpen )
{
fprintf(mExportFile,"[%s]\t(%.2lf,%.2lf,%.2lf)\t(%.2lf,%.2lf,%.2lf)\n",
(char*)pTime.GetTimeString(),
mPosition[0],
mPosition[1],
mPosition[2],
mRotation[0],
mRotation[1],
mRotation[2]
);
}
return true;
}
/************************************************
* Write the new position values into the hardware abstraction.
************************************************/
void ORDeviceOutputHardware::WritePos( double* pPos )
{
mPosition[0] = pPos[0];
mPosition[1] = pPos[1];
mPosition[2] = pPos[2];
}
/************************************************
* Write the new rotation values into the hardware abstraction.
************************************************/
void ORDeviceOutputHardware::WriteRot( double* pRot )
{
mRotation[0] = pRot[0];
mRotation[1] = pRot[1];
mRotation[2] = pRot[2];
}