mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Allow polling for messages from C
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef __NEOMESSAGE_H_
|
||||
#define __NEOMESSAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t netid;
|
||||
uint8_t type;
|
||||
char header[4];
|
||||
const uint8_t* data;
|
||||
size_t length;
|
||||
uint64_t timestamp;
|
||||
char reserved[8];
|
||||
} neomessage_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t netid;
|
||||
uint8_t type;
|
||||
uint32_t arbid;
|
||||
const uint8_t* data;
|
||||
size_t length;
|
||||
uint64_t timestamp;
|
||||
char reserved[8];
|
||||
} neomessage_can_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "communication/message/include/message.h"
|
||||
|
||||
namespace icsneo {
|
||||
neomessage_t CreateNeoMessage(const Message& message);
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "communication/message/include/neomessage.h"
|
||||
#include "communication/message/include/canmessage.h"
|
||||
|
||||
using namespace icsneo;
|
||||
|
||||
neomessage_t icsneo::CreateNeoMessage(const 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();
|
||||
neomessage_t neomsg = { 0 }; // Clear out the memory
|
||||
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;
|
||||
|
||||
switch(type) {
|
||||
case Network::Type::CAN:
|
||||
((neomessage_can_t*)&neomsg)->arbid = ((const CANMessage*)&message)->arbid;
|
||||
break;
|
||||
}
|
||||
|
||||
return neomsg;
|
||||
}
|
||||
Reference in New Issue
Block a user