Skip to content
Snippets Groups Projects
Commit d192be27 authored by Simon Ottenhaus's avatar Simon Ottenhaus
Browse files

fixed segmentation fault

parent a6819088
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ if (Eigen3_FOUND)
${Eigen3_INCLUDE_DIR})
endif()
set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants WeissHapticSensorListener RobotAPIUnits)
set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants WeissHapticSensorListener RobotAPIUnits RobotAPIInterfaces)
set(EXE_SOURCE main.cpp WeissHapticSensorApp.h)
......
......@@ -8,7 +8,7 @@ if (Eigen3_FOUND)
${Eigen3_INCLUDE_DIR})
endif()
set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants WeissHapticSensor RobotAPIUnits)
set(COMPONENT_LIBS ArmarXInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants WeissHapticSensor RobotAPIUnits RobotAPIInterfaces)
set(EXE_SOURCE main.cpp WeissHapticSensorsUnitApp.h)
......
......@@ -10,16 +10,13 @@
AbstractInterface::AbstractInterface()
: connected(false), log(NULL)
: connected(false)
{
}
AbstractInterface::~AbstractInterface() {
if(log != NULL)
{
delete log;
}
AbstractInterface::~AbstractInterface()
{
}
int AbstractInterface::read(unsigned char *buf, unsigned int len)
......@@ -47,20 +44,6 @@ int AbstractInterface::write(unsigned char *buf, unsigned int len)
Response AbstractInterface::submitCmd( unsigned char id, unsigned char *payload, unsigned int len, bool pending )
{
/*int res;
// Check if we're connected
if ( !connected )
{
throw TransmissionException("Interface not connected");
}
// Send command
res = send( id, len, payload );
if ( res < 0 )
{
throw TransmissionException("Message send failed");
}*/
fireAndForgetCmd(id, payload, len, pending);
return receive(pending, id);
}
......@@ -86,7 +69,7 @@ void AbstractInterface::fireAndForgetCmd( unsigned char id, unsigned char *paylo
void AbstractInterface::startLogging(std::string file)
{
log = new BinaryLogger(file);
log.reset(new BinaryLogger(file));
}
void AbstractInterface::logText(std::string message)
......@@ -197,8 +180,12 @@ int AbstractInterface::receive( msg_t *msg )
msg->len = make_short( header[1], header[2] );
// Allocate space for payload and checksum
msg->data.resize( msg->len + 2u );
//msg->data.resize( msg->len + 2u );
//if ( !msg->data ) return -1;
//boost::shared_ptr<unsigned char[]> data(new unsigned char[ msg->len + 2u ]);
unsigned char* data = new unsigned char[ msg->len + 2u ];
// Read payload and checksum
/*int maxReads = 10;
......@@ -206,7 +193,7 @@ int AbstractInterface::receive( msg_t *msg )
int dataOffset = 0;
while ( maxReads > 0 && remaining > 0)
{
int read = this->read( msg->data.data() + dataOffset, remaining );
int read = this->read( data + dataOffset, remaining );
dataOffset += read;
remaining -= read;
maxReads--;
......@@ -223,9 +210,10 @@ int AbstractInterface::receive( msg_t *msg )
// Read payload and checksum:
// payload: msg->len
// checksum: 2 byte
int read = this->read( msg->data.data(), msg->len + 2 );
if (read != msg->len + 2)
int read = this->read( data, msg->len + 2 );
if (read != (int)msg->len + 2)
{
delete[] data;
throw TransmissionException(str(boost::format("Not enough data (%d, expected %d), Command = %02X") % res % (msg->len + 2) % msg->id));
}
......@@ -239,13 +227,16 @@ int AbstractInterface::receive( msg_t *msg )
}*/
// Check checksum
checksum = Checksum::Update_crc16( msg->data.data(), msg->len + 2, checksum );
checksum = Checksum::Update_crc16( data, msg->len + 2, checksum );
if ( checksum != 0 )
{
delete[] data;
logText("CHECKSUM ERROR");
throw ChecksumErrorException("Checksum error");
}
msg->data = std::vector<unsigned char>(data, data + msg->len + 2);
delete[] data;
logText("receive done.");
return msg->len + 8;
}
......@@ -281,6 +272,7 @@ int AbstractInterface::send(unsigned char id, unsigned int len, unsigned char *d
res = write( buf, 6 + len + 2 );
if ( res < 6 + (int)len + 2 )
{
delete[] buf;
close();
throw TransmissionException("Failed to submit message checksum");
//cerr << "Failed to submit message checksum" << endl;
......
......@@ -4,6 +4,7 @@
#include <string>
#include "Types.h"
#include "BinaryLogger.h"
#include <boost/shared_ptr.hpp>
#define MSG_PREAMBLE_BYTE 0xaa
......@@ -55,7 +56,7 @@ protected:
private:
friend std::ostream& operator<<(std::ostream&, const AbstractInterface&);
BinaryLogger* log;
boost::shared_ptr<BinaryLogger> log;
};
std::ostream& operator<<(std::ostream &strm, const AbstractInterface &a);
......
......@@ -38,6 +38,7 @@ SerialInterface::SerialInterface(const char *device, unsigned int bitrate)
{
this->device = device;
this->bitrate = bitrate;
this->fd = -1;
}
SerialInterface::~SerialInterface() {
......@@ -134,19 +135,23 @@ int SerialInterface::readInternal( unsigned char *buf, unsigned int len)
int SerialInterface::blockingReadAll(unsigned char *buf, unsigned int len)
{
int readData = 0;
int dataToRead = len;
while (1)
{
int res = ::read( fd, buf, len );
int res = ::read( fd, buf, dataToRead );
if (res < 0)
{
return res;
}
readData += res;
dataToRead -= res;
buf += res;
if (readData >= len)
if (dataToRead == 0)
{
return readData;
return len;
}
if (dataToRead < 0)
{
throw new std::runtime_error("Internal error: dataToRead < 0");
}
usleep(1);
}
......
......@@ -6,7 +6,7 @@
using namespace armarx;
WeissHapticSensor::WeissHapticSensor(std::string device)
: device(device)
: device(device), connected(false)
{
sensorTask = new RunningTask<WeissHapticSensor>(this, &WeissHapticSensor::frameAcquisitionTaskLoop);
boost::smatch match;
......
......@@ -13,6 +13,8 @@ if (Eigen3_FOUND AND Simox_FOUND)
${Simox_INCLUDE_DIRS})
endif()
message(status ${Eigen3_INCLUDE_DIR})
set(LIB_NAME RobotAPIUnits)
set(LIB_VERSION 0.1.0)
set(LIB_SOVERSION 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment