Skip to content

Commit

Permalink
improve USB behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
whoenig committed Jan 16, 2019
1 parent 08921f9 commit 2d3557e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/crazyflie_cpp/Crazyflie.h
Expand Up @@ -110,6 +110,8 @@ class Crazyflie
const std::string& link_uri,
Logger& logger = EmptyLogger);

virtual ~Crazyflie();

void logReset();

void sendSetpoint(
Expand Down
8 changes: 8 additions & 0 deletions src/Crazyflie.cpp
Expand Up @@ -124,6 +124,14 @@ Crazyflie::Crazyflie(

}

Crazyflie::~Crazyflie()
{
for (size_t i = 0; i < MAX_USB; ++i) {
delete g_crazyflieUSB[i];
}

}

void Crazyflie::logReset()
{
crtpLogResetRequest request;
Expand Down
23 changes: 19 additions & 4 deletions src/CrazyflieUSB.cpp
Expand Up @@ -71,13 +71,28 @@ void CrazyflieUSB::sendPacket(
(unsigned char*)&result.data[0],
sizeof(result) - 2,
&transferred,
/*timeout*/ 1000);
if (status != LIBUSB_SUCCESS) {
/*timeout*/ 1);
if ( status != LIBUSB_SUCCESS
&& status != LIBUSB_ERROR_TIMEOUT) {
throw std::runtime_error(libusb_error_name(status));
}
result.ack = true;
if (status == LIBUSB_SUCCESS) {
result.ack = true;
result.size = transferred;
}

// std::cout << "sendPacket: ";
// for (uint32_t i = 0; i < length; ++i) {
// std::cout << std::hex << (int)data[i] << " ";
// }
// std::cout << std::endl;
// std::cout << " ack: " << (int)result.ack << " " << (int)result.size << " ";
// for (uint32_t i = 0; i < result.size; ++i) {
// std::cout << std::hex << (int)result.data[i] << " ";
// }
// std::cout << std::endl;


result.size = transferred;
}

void CrazyflieUSB::sendPacketNoAck(
Expand Down

0 comments on commit 2d3557e

Please sign in to comment.