Commit 00500527 authored by Andreu Corominas-Murtra's avatar Andreu Corominas-Murtra
Browse files

Minor changes and code cleaning

parent 45110a41
#include "asterx1_gps.h"
CasteRx1::CasteRx1(const string & hwPortName, const int acqRateIndex)
CasteRx1::CasteRx1(const string & hwPortName, const int acqRate)
{
status = 0;
config.portName = hwPortName;
config.acqPeriod = acqPeriodValues[acqRateIndex];
config.acqPeriod = acqPeriodValues[acqRate];
}
CasteRx1::~CasteRx1()
......@@ -12,14 +12,14 @@ CasteRx1::~CasteRx1()
blockList.clear();
if( (status & ACQUISITION_RUNNING) ) stopAcquisition();
if( (status & DEVICE_OPEN) ) closeDevice();
delete serialPort;
cout << "CasteRx1::~CasteRx1(). End of CasteRx1 destructor" << endl; //bye bye message
}
int CasteRx1::openDevice(int xx)
int CasteRx1::openDevice()
{
cout << xx << endl;
TRS232_config serialConfig;
int retValue = BASIC_SUCCESS;
TRS232_config serialConfig;
try{
serialPort = new CRS232(config.portName); //creates a new object to manage serial connection
......@@ -84,13 +84,11 @@ int CasteRx1::closeDevice()
retValue = PORT_CLOSE_ERROR;
//status |= DEVICE_OPEN; //close() has failed , so it is still opened
}
}
if ( retValue == BASIC_SUCCESS ) //if close() is successful, we delete the object
{
status &= ~DEVICE_OPEN;
cout << "CasteRx1::closeDevice(). SUCCESS. Serial port " << config.portName << " closed successfully." << endl;
delete serialPort;
}
return retValue;
......@@ -102,7 +100,7 @@ int CasteRx1::startAcquisition()
sbfBlockManager *blockMng;
string cmnd;
//enables commands as input at USB1
//enables commands at USB1 device input
retValue += sendCommand("setDataInOut,USB1,CMD,none\n");
//stops data transmission if it was running
......@@ -138,7 +136,6 @@ int CasteRx1::startAcquisition()
cmnd.append(config.acqPeriod);
cmnd.append("\n");
retValue += sendCommand(cmnd);
//retValue += sendCommand("setSBFOutput,Stream1,USB1,Group1,msec500\n");
if ( retValue == BASIC_SUCCESS*11 ) //success on all commands
{
......@@ -221,7 +218,7 @@ int CasteRx1::readDataFromDevice()
retValue += readNbytes(&buffer[0],2,DATA_TIMEOUT);//reads transmitted crc value
crcValue = getUI2(&buffer[0]); //decodes crc value
retValue += readNbytes(&buffer[0],2,DATA_TIMEOUT);//reads block id field
blockId = (buffer[0] & 0xff)|((buffer[1] & 0x1f)<<8);//decodes blockId (usies only the 13 LS bits)
blockId = (buffer[0] & 0xff)|((buffer[1] & 0x1f)<<8);//decodes blockId (uses only the 13 LS bits)
retValue += readNbytes(&buffer[2],2,DATA_TIMEOUT);//reads block length
blockLength = getUI2(&buffer[2]);//decodes block length (in bytes)
......
......@@ -131,59 +131,69 @@ const bool inDEGREES = 1;
class CasteRx1
{
public:
/**
Constructor: just catch the name of the serial port
/** \brief Default constructor
*
* Constructor. Requires port file name and, optionally, acquisition rate.
*
*/
CasteRx1(const string & hwPortName = "/dev/ttyACM0", const int acqRateIndex = MSEC500);
CasteRx1(const string & hwPortName = "/dev/ttyACM0", const int acqRate = MSEC500);
/**
Destructor: Stops acquisition in case it was running and closes serial Port in case it was opened.
/** \brief Destructor
*
* Destructor: Stops acquisition in case it was running and closes serial Port in case it was opened.
*
*/
virtual ~CasteRx1();
/**
Opens serial communications and starts serial comm thread.
If success , sets status bit DEVICE_OPEN.
Return values are:
BASIC_SUCCESS
PORT_OPEN_ERROR if thread can't be created or port can't be opened
PORT_CONFIG_ERROR if port can't be configured
/** \brief Open and configure serial device.
*
* Open and configure serial device to 8N1 Byte transmission.
* Launches a thread for serial in/out comms
* Return values are:
* BASIC_SUCCESS
* PORT_OPEN_ERROR if thread can't be created or port can't be opened
* PORT_CONFIG_ERROR if port can't be configured
*/
int openDevice(int xx=3);
int openDevice();
/**
Closes serial comm's , stops comm thread and deletes comm object.
If success , resets status bit DEVICE_OPEN.
Return values are:
BASIC_SUCCESS
PORT_CLOSE_ERROR
/** \brief Closes serial comm
*
* Closes serial comm's , stops comm thread and deletes comm object.
* If success , resets status bit DEVICE_OPEN.
* Return values are:
* BASIC_SUCCESS
* PORT_CLOSE_ERROR
*/
int closeDevice();
/**
Configures the device to perform some signal processing basics for mobile robotics.
Starts a mode of operation of continuos data flow from the device at a rate of 2Hz.
Return values are:
BASIC_SUCCESS
ASTERX1_CONFIG_ERROR
/** \brief Starts basic data acquisition
*
* Configures the device to perform some signal processing basics for mobile robotics.
* Starts a mode of operation of continuos data flow from the device at a rate of 2Hz.
* Return values are:
* BASIC_SUCCESS
* ASTERX1_CONFIG_ERROR
*/
int startAcquisition();
/**
Stops mode of operation of continuous data flow
Return values are:
BASIC_SUCCESS when device stop is ok
ASTERX1_STOPPINTG_ERROR otherwise.
/** \brief Stops acquisition
*
* Stops continuous acquisition mode
* Return values are:
* BASIC_SUCCESS when device stop is ok
* ASTERX1_STOPPINTG_ERROR otherwise.
*/
int stopAcquisition();
/**
Reads current data produced by the device. Ends when all data blocks requested have been received.
Sets status and all data fields.
Return values are:
BASIC_SUCCESS if all blocks are successfully decodes.
ACQUISITION_ERROR otherwise.
Afterwards, call getStatus() to check for gps availability.
/** \brief Decodes the device SBF stream
*
* Reads current data produced by the device. Ends when all data blocks requested have been received.
* Sets status and all data fields.
* Return values are:
* BASIC_SUCCESS if all blocks are successfully decodes.
* ACQUISITION_ERROR otherwise.
*
* After calling this function, call getStatus() to check for gps availability.
*/
int readDataFromDevice();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment