CAN and CAN FD transmit implemented

This commit is contained in:
Paul Hollinsky
2018-10-18 17:39:37 -04:00
parent dd99f82324
commit d037709963
8 changed files with 213 additions and 82 deletions
+3 -1
View File
@@ -119,12 +119,14 @@ typedef struct {
#ifdef __cplusplus
#include "communication/message/include/message.h"
#include <memory>
static_assert(sizeof(neomessage_can_t) == sizeof(neomessage_t), "All types of neomessage_t must be the same size!");
namespace icsneo {
neomessage_t CreateNeoMessage(const Message& message);
neomessage_t CreateNeoMessage(const std::shared_ptr<Message> message);
std::shared_ptr<Message> CreateMessageFromNeoMessage(const neomessage_t* neomessage);
}
#endif
+34 -13
View File
@@ -3,27 +3,27 @@
using namespace icsneo;
neomessage_t icsneo::CreateNeoMessage(const Message& message) {
neomessage_t icsneo::CreateNeoMessage(const std::shared_ptr<Message> message) {
// This function is not responsible for storing the message!
// Keep the shared_ptr around for the lifetime of the data access
const auto type = message.network.getType();
const auto type = message->network.getType();
neomessage_t neomsg = {}; // Clear out the memory
neomsg.netid = (uint32_t)message.network.getNetID();
neomsg.netid = (uint32_t)message->network.getNetID();
neomsg.type = (uint8_t)type;
neomsg.length = message.data.size();
neomsg.data = message.data.data();
neomsg.timestamp = message.timestamp;
neomsg.length = message->data.size();
neomsg.data = message->data.data();
neomsg.timestamp = message->timestamp;
switch(type) {
case Network::Type::CAN: {
neomessage_can_t& can = *(neomessage_can_t*)&neomsg;
const CANMessage& canmsg = *(const CANMessage*)&message;
can.arbid = canmsg.arbid;
can.status.extendedFrame = canmsg.isExtended;
can.status.remoteFrame = canmsg.isRemote;
can.status.canfdRTR = canmsg.isRemote;
can.status.canfdFDF = canmsg.isCANFD;
can.status.canfdBRS = canmsg.baudrateSwitch;
auto canmsg = std::static_pointer_cast<CANMessage>(message);
can.arbid = canmsg->arbid;
can.status.extendedFrame = canmsg->isExtended;
can.status.remoteFrame = canmsg->isRemote;
can.status.canfdRTR = canmsg->isRemote;
can.status.canfdFDF = canmsg->isCANFD;
can.status.canfdBRS = canmsg->baudrateSwitch;
break;
}
default:
@@ -32,4 +32,25 @@ neomessage_t icsneo::CreateNeoMessage(const Message& message) {
}
return neomsg;
}
std::shared_ptr<Message> icsneo::CreateMessageFromNeoMessage(const neomessage_t* neomessage) {
const Network network = neomessage->netid;
switch(network.getType()) {
case Network::Type::CAN: {
neomessage_can_t& can = *(neomessage_can_t*)neomessage;
auto canmsg = std::make_shared<CANMessage>();
canmsg->network = network;
canmsg->data.insert(canmsg->data.end(), can.data, can.data + can.length);
canmsg->arbid = can.arbid;
canmsg->isExtended = can.status.extendedFrame;
canmsg->isRemote = can.status.remoteFrame | can.status.canfdRTR;
canmsg->isCANFD = can.status.canfdFDF;
canmsg->baudrateSwitch = can.status.canfdBRS;
return canmsg;
}
default:
// TODO Implement others
return std::shared_ptr<Message>();
}
}