Skip to content
Permalink
Browse files
Fixed write bug
  • Loading branch information
David committed Dec 7, 2022
1 parent 5e2ab3a commit ede534b644a0d09fd436ccc0a0f37b77822cd8a8
Showing 1 changed file with 11 additions and 31 deletions.
@@ -67,8 +67,9 @@ bool can_close( const int socket )
* @brief Passes call to can::_read<can_frame>() to read standard CAN frame.
*
* @pre must call connect() successfully first.
* @param socket Socket identifer as returned from can::connect().
* @return const can_frame
* @param socket Socket identifer as returned from can_connect().
* @param frame CAN frame variable to place read data.
* @return Success.
*/
bool can_read( const int socket, struct can_frame* frame )
{
@@ -79,8 +80,9 @@ bool can_read( const int socket, struct can_frame* frame )
* @brief Passes call to can::_read<canfd_frame>() to read CANFD frame.
*
* @pre must call connectfd() successfully first.
* @param socket Socket identifer as returned from can::connect().
* @return const canfd_frame
* @param socket Socket identifer as returned from can_connect().
* @param frame CAN frame variable to place read data.
* @return Success.
*/
bool can_readfd( const int socket, struct canfd_frame* frame )
{
@@ -90,47 +92,25 @@ bool can_readfd( const int socket, struct canfd_frame* frame )
/**
* @brief Passes call to can::_write<can_frame>() to write standard CAN frame.
*
* @param socket Socket identifer as returned from can::connect().
* @param socket Socket identifer as returned from can_connect().
* @param frame CAN frame to be sent.
* @return Success.
*/
bool can_write( const int socket, struct can_frame* frame )
{
return write( socket, &frame, sizeof(struct can_frame) ) == sizeof(struct can_frame);
return write( socket, frame, sizeof(struct can_frame) ) == sizeof(struct can_frame);
}

/**
* @brief Passes call to can::_write<canfd_frame>() to write CANFD frame.
*
* @param socket Socket identifer as returned from can::connect().
* @param frame CANFD frame to be sent.
* @return Success.
*/
bool can_writefd( const int socket, struct canfd_frame* frame )
{
return write( socket, &frame, sizeof(struct canfd_frame) ) == sizeof(struct canfd_frame);
}

/*
std::ostream& operator<<( std::ostream &os, const can_frame& frame )
{
os << "0x" << std::setw(3) << std::hex << frame.can_id <<
" [" << static_cast<int>(frame.can_dlc) << ']';
for( int i=0; i<frame.can_dlc; ++i )
os << ' ' << std::uppercase << std::setfill('0') << std::setw(2)
<< static_cast<int>(frame.data[i]);
return os;
return write( socket, frame, sizeof(struct canfd_frame) ) == sizeof(struct canfd_frame);
}

std::ostream& operator<<( std::ostream &os, const canfd_frame& frame )
{
os << "0x" << std::setw(3) << std::hex << frame.can_id <<
" [" << static_cast<int>(frame.len) << ']';
os << std::uppercase << std::setfill('0') << std::setw(2);
for( int i=0; i<frame.len; ++i )
os << ' ' << std::uppercase << std::setfill('0') << std::setw(2)
<< static_cast<int>(frame.data[i]);
return os;
}*/

#endif

0 comments on commit ede534b

Please sign in to comment.