mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Repo: Normalize source files to LF
This commit is contained in:
@@ -1,50 +1,50 @@
|
||||
#ifndef __MESSAGECALLBACK_H_
|
||||
#define __MESSAGECALLBACK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/filter/messagefilter.h"
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class MessageCallback {
|
||||
public:
|
||||
typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback;
|
||||
|
||||
MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f)
|
||||
: callback(cb), filter(f ? f : std::make_shared<MessageFilter>()) {
|
||||
if(!cb)
|
||||
throw std::bad_function_call();
|
||||
}
|
||||
|
||||
MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter())
|
||||
: MessageCallback(cb, std::make_shared<MessageFilter>(f)) {}
|
||||
|
||||
// Allow the filter to be placed first if the user wants (maybe in the case of a lambda)
|
||||
MessageCallback(std::shared_ptr<MessageFilter> f, fn_messageCallback cb)
|
||||
: MessageCallback(cb, f) {}
|
||||
MessageCallback(MessageFilter f, fn_messageCallback cb)
|
||||
: MessageCallback(cb, std::make_shared<MessageFilter>(f)) {}
|
||||
|
||||
virtual bool callIfMatch(const std::shared_ptr<Message>& message) const {
|
||||
bool ret = filter->match(message);
|
||||
if(ret)
|
||||
callback(message);
|
||||
return ret;
|
||||
}
|
||||
const MessageFilter& getFilter() const { return *filter; }
|
||||
const fn_messageCallback& getCallback() const { return callback; }
|
||||
|
||||
protected:
|
||||
const fn_messageCallback callback;
|
||||
const std::shared_ptr<MessageFilter> filter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifndef __MESSAGECALLBACK_H_
|
||||
#define __MESSAGECALLBACK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/filter/messagefilter.h"
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class MessageCallback {
|
||||
public:
|
||||
typedef std::function< void( std::shared_ptr<Message> ) > fn_messageCallback;
|
||||
|
||||
MessageCallback(fn_messageCallback cb, std::shared_ptr<MessageFilter> f)
|
||||
: callback(cb), filter(f ? f : std::make_shared<MessageFilter>()) {
|
||||
if(!cb)
|
||||
throw std::bad_function_call();
|
||||
}
|
||||
|
||||
MessageCallback(fn_messageCallback cb, MessageFilter f = MessageFilter())
|
||||
: MessageCallback(cb, std::make_shared<MessageFilter>(f)) {}
|
||||
|
||||
// Allow the filter to be placed first if the user wants (maybe in the case of a lambda)
|
||||
MessageCallback(std::shared_ptr<MessageFilter> f, fn_messageCallback cb)
|
||||
: MessageCallback(cb, f) {}
|
||||
MessageCallback(MessageFilter f, fn_messageCallback cb)
|
||||
: MessageCallback(cb, std::make_shared<MessageFilter>(f)) {}
|
||||
|
||||
virtual bool callIfMatch(const std::shared_ptr<Message>& message) const {
|
||||
bool ret = filter->match(message);
|
||||
if(ret)
|
||||
callback(message);
|
||||
return ret;
|
||||
}
|
||||
const MessageFilter& getFilter() const { return *filter; }
|
||||
const fn_messageCallback& getCallback() const { return callback; }
|
||||
|
||||
protected:
|
||||
const fn_messageCallback callback;
|
||||
const std::shared_ptr<MessageFilter> filter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,25 +1,25 @@
|
||||
#ifndef __CANMESSAGE_H_
|
||||
#define __CANMESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class CANMessage : public Frame {
|
||||
public:
|
||||
uint32_t arbid;
|
||||
uint8_t dlcOnWire;
|
||||
bool isRemote = false; // Not allowed if CAN FD
|
||||
bool isExtended = false;
|
||||
bool isCANFD = false;
|
||||
bool baudrateSwitch = false; // CAN FD only
|
||||
bool errorStateIndicator = false; // CAN FD only
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifndef __CANMESSAGE_H_
|
||||
#define __CANMESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class CANMessage : public Frame {
|
||||
public:
|
||||
uint32_t arbid;
|
||||
uint8_t dlcOnWire;
|
||||
bool isRemote = false; // Not allowed if CAN FD
|
||||
bool isExtended = false;
|
||||
bool isCANFD = false;
|
||||
bool baudrateSwitch = false; // CAN FD only
|
||||
bool errorStateIndicator = false; // CAN FD only
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,68 +1,68 @@
|
||||
#ifndef __MESSAGEFILTER_H_
|
||||
#define __MESSAGEFILTER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class MessageFilter {
|
||||
public:
|
||||
MessageFilter() {}
|
||||
MessageFilter(Message::Type type) : includeInternalInAny(neomessagetype_t(type) & 0x8000), messageType(type) {}
|
||||
MessageFilter(Network::NetID netid) : MessageFilter(Network::GetTypeOfNetID(netid), netid) {}
|
||||
MessageFilter(Network::Type type, Network::NetID net = Network::NetID::Any) : networkType(type), netid(net) {
|
||||
// If a Network::Type::Internal is used, we want to also get internal Message::Types
|
||||
// The NetID we want may be in there
|
||||
includeInternalInAny = (networkType == Network::Type::Internal);
|
||||
}
|
||||
virtual ~MessageFilter() = default;
|
||||
// When getting "all" types of messages, include the ones marked as "internal only"
|
||||
bool includeInternalInAny = false;
|
||||
|
||||
virtual bool match(const std::shared_ptr<Message>& message) const {
|
||||
if(!matchMessageType(message->type))
|
||||
return false;
|
||||
|
||||
if(message->type == Message::Type::Frame || message->type == Message::Type::Main51 ||
|
||||
message->type == Message::Type::RawMessage || message->type == Message::Type::ReadSettings) {
|
||||
RawMessage& frame = *static_cast<RawMessage*>(message.get());
|
||||
if(!matchNetworkType(frame.network.getType()))
|
||||
return false;
|
||||
if(!matchNetID(frame.network.getNetID()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
Message::Type messageType = Message::Type::Invalid; // Used here for "any"
|
||||
bool matchMessageType(Message::Type mtype) const {
|
||||
if(messageType == Message::Type::Invalid && ((neomessagetype_t(mtype) & 0x8000) == 0 || includeInternalInAny))
|
||||
return true;
|
||||
return messageType == mtype;
|
||||
}
|
||||
|
||||
Network::Type networkType = Network::Type::Any;
|
||||
bool matchNetworkType(Network::Type mtype) const {
|
||||
if(networkType == Network::Type::Any && (mtype != Network::Type::Internal || includeInternalInAny))
|
||||
return true;
|
||||
return networkType == mtype;
|
||||
}
|
||||
|
||||
Network::NetID netid = Network::NetID::Any;
|
||||
bool matchNetID(Network::NetID mnetid) const {
|
||||
if(netid == Network::NetID::Any)
|
||||
return true;
|
||||
return netid == mnetid;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifndef __MESSAGEFILTER_H_
|
||||
#define __MESSAGEFILTER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class MessageFilter {
|
||||
public:
|
||||
MessageFilter() {}
|
||||
MessageFilter(Message::Type type) : includeInternalInAny(neomessagetype_t(type) & 0x8000), messageType(type) {}
|
||||
MessageFilter(Network::NetID netid) : MessageFilter(Network::GetTypeOfNetID(netid), netid) {}
|
||||
MessageFilter(Network::Type type, Network::NetID net = Network::NetID::Any) : networkType(type), netid(net) {
|
||||
// If a Network::Type::Internal is used, we want to also get internal Message::Types
|
||||
// The NetID we want may be in there
|
||||
includeInternalInAny = (networkType == Network::Type::Internal);
|
||||
}
|
||||
virtual ~MessageFilter() = default;
|
||||
// When getting "all" types of messages, include the ones marked as "internal only"
|
||||
bool includeInternalInAny = false;
|
||||
|
||||
virtual bool match(const std::shared_ptr<Message>& message) const {
|
||||
if(!matchMessageType(message->type))
|
||||
return false;
|
||||
|
||||
if(message->type == Message::Type::Frame || message->type == Message::Type::Main51 ||
|
||||
message->type == Message::Type::RawMessage || message->type == Message::Type::ReadSettings) {
|
||||
RawMessage& frame = *static_cast<RawMessage*>(message.get());
|
||||
if(!matchNetworkType(frame.network.getType()))
|
||||
return false;
|
||||
if(!matchNetID(frame.network.getNetID()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
Message::Type messageType = Message::Type::Invalid; // Used here for "any"
|
||||
bool matchMessageType(Message::Type mtype) const {
|
||||
if(messageType == Message::Type::Invalid && ((neomessagetype_t(mtype) & 0x8000) == 0 || includeInternalInAny))
|
||||
return true;
|
||||
return messageType == mtype;
|
||||
}
|
||||
|
||||
Network::Type networkType = Network::Type::Any;
|
||||
bool matchNetworkType(Network::Type mtype) const {
|
||||
if(networkType == Network::Type::Any && (mtype != Network::Type::Internal || includeInternalInAny))
|
||||
return true;
|
||||
return networkType == mtype;
|
||||
}
|
||||
|
||||
Network::NetID netid = Network::NetID::Any;
|
||||
bool matchNetID(Network::NetID mnetid) const {
|
||||
if(netid == Network::NetID::Any)
|
||||
return true;
|
||||
return netid == mnetid;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,30 +1,30 @@
|
||||
#ifndef __ISO9141MESSAGE_H_
|
||||
#define __ISO9141MESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include <array>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class ISO9141Message : public Frame {
|
||||
public:
|
||||
std::array<uint8_t, 3> header;
|
||||
bool isInit = false;
|
||||
bool isBreak = false;
|
||||
bool framingError = false;
|
||||
bool overflowError = false;
|
||||
bool parityError = false;
|
||||
bool rxTimeoutError = false;
|
||||
// Checksum not yet implemted, it's just at the end of the data if enabled for now
|
||||
// bool checksumError = false;
|
||||
// bool hasChecksum = false;
|
||||
// uint8_t checksum = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifndef __ISO9141MESSAGE_H_
|
||||
#define __ISO9141MESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include <array>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class ISO9141Message : public Frame {
|
||||
public:
|
||||
std::array<uint8_t, 3> header;
|
||||
bool isInit = false;
|
||||
bool isBreak = false;
|
||||
bool framingError = false;
|
||||
bool overflowError = false;
|
||||
bool parityError = false;
|
||||
bool rxTimeoutError = false;
|
||||
// Checksum not yet implemted, it's just at the end of the data if enabled for now
|
||||
// bool checksumError = false;
|
||||
// bool hasChecksum = false;
|
||||
// uint8_t checksum = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -1,77 +1,77 @@
|
||||
#ifndef __MESSAGE_H_
|
||||
#define __MESSAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
typedef uint16_t neomessagetype_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
#include <vector>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Message {
|
||||
public:
|
||||
enum class Type : neomessagetype_t {
|
||||
Frame = 0,
|
||||
|
||||
CANErrorCount = 0x100,
|
||||
|
||||
// Past 0x8000 are all for internal use only
|
||||
Invalid = 0x8000,
|
||||
RawMessage = 0x8001,
|
||||
ReadSettings = 0x8002,
|
||||
ResetStatus = 0x8003,
|
||||
DeviceVersion = 0x8004,
|
||||
Main51 = 0x8005,
|
||||
FlexRayControl = 0x8006,
|
||||
EthernetPhyRegister = 0x8007,
|
||||
LogicalDiskInfo = 0x8008,
|
||||
};
|
||||
|
||||
Message(Type t) : type(t) {}
|
||||
virtual ~Message() = default;
|
||||
const Type type;
|
||||
uint64_t timestamp = 0;
|
||||
};
|
||||
|
||||
class RawMessage : public Message {
|
||||
public:
|
||||
RawMessage(Message::Type type = Message::Type::RawMessage) : Message(type) {}
|
||||
RawMessage(Message::Type type, Network net) : Message(type), network(net) {}
|
||||
RawMessage(Network net) : Message(Message::Type::RawMessage), network(net) {}
|
||||
RawMessage(Network net, std::vector<uint8_t> d) : Message(Message::Type::RawMessage), network(net), data(d) {}
|
||||
|
||||
Network network;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
class Frame : public RawMessage {
|
||||
public:
|
||||
Frame() : RawMessage(Message::Type::Frame) {}
|
||||
|
||||
uint16_t description = 0;
|
||||
bool transmitted = false;
|
||||
bool error = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __ICSNEOC_H_
|
||||
|
||||
#define ICSNEO_MESSAGE_TYPE_FRAME (0x0)
|
||||
#define ICSNEO_MESSAGE_TYPE_CAN_ERROR_COUNT (0x100)
|
||||
#define ICSNEO_MESSAGE_TYPE_INVALID (0x8000)
|
||||
#define ICSNEO_MESSAGE_TYPE_RAW_MESSAGE (0x8001)
|
||||
#define ICSNEO_MESSAGE_TYPE_READ_SETTINGS (0x8002)
|
||||
#define ICSNEO_MESSAGE_TYPE_RESET_STATUS (0x8003)
|
||||
#define ICSNEO_MESSAGE_TYPE_DEVICE_VERSION (0x8004)
|
||||
#define ICSNEO_MESSAGE_TYPE_MAIN51 (0x8005)
|
||||
#define ICSNEO_MESSAGE_TYPE_FLEXRAY_CONTROL (0x8006)
|
||||
|
||||
#endif // __ICSNEOC_H_
|
||||
|
||||
#ifndef __MESSAGE_H_
|
||||
#define __MESSAGE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
typedef uint16_t neomessagetype_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/network.h"
|
||||
#include <vector>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Message {
|
||||
public:
|
||||
enum class Type : neomessagetype_t {
|
||||
Frame = 0,
|
||||
|
||||
CANErrorCount = 0x100,
|
||||
|
||||
// Past 0x8000 are all for internal use only
|
||||
Invalid = 0x8000,
|
||||
RawMessage = 0x8001,
|
||||
ReadSettings = 0x8002,
|
||||
ResetStatus = 0x8003,
|
||||
DeviceVersion = 0x8004,
|
||||
Main51 = 0x8005,
|
||||
FlexRayControl = 0x8006,
|
||||
EthernetPhyRegister = 0x8007,
|
||||
LogicalDiskInfo = 0x8008,
|
||||
};
|
||||
|
||||
Message(Type t) : type(t) {}
|
||||
virtual ~Message() = default;
|
||||
const Type type;
|
||||
uint64_t timestamp = 0;
|
||||
};
|
||||
|
||||
class RawMessage : public Message {
|
||||
public:
|
||||
RawMessage(Message::Type type = Message::Type::RawMessage) : Message(type) {}
|
||||
RawMessage(Message::Type type, Network net) : Message(type), network(net) {}
|
||||
RawMessage(Network net) : Message(Message::Type::RawMessage), network(net) {}
|
||||
RawMessage(Network net, std::vector<uint8_t> d) : Message(Message::Type::RawMessage), network(net), data(d) {}
|
||||
|
||||
Network network;
|
||||
std::vector<uint8_t> data;
|
||||
};
|
||||
|
||||
class Frame : public RawMessage {
|
||||
public:
|
||||
Frame() : RawMessage(Message::Type::Frame) {}
|
||||
|
||||
uint16_t description = 0;
|
||||
bool transmitted = false;
|
||||
bool error = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#ifdef __ICSNEOC_H_
|
||||
|
||||
#define ICSNEO_MESSAGE_TYPE_FRAME (0x0)
|
||||
#define ICSNEO_MESSAGE_TYPE_CAN_ERROR_COUNT (0x100)
|
||||
#define ICSNEO_MESSAGE_TYPE_INVALID (0x8000)
|
||||
#define ICSNEO_MESSAGE_TYPE_RAW_MESSAGE (0x8001)
|
||||
#define ICSNEO_MESSAGE_TYPE_READ_SETTINGS (0x8002)
|
||||
#define ICSNEO_MESSAGE_TYPE_RESET_STATUS (0x8003)
|
||||
#define ICSNEO_MESSAGE_TYPE_DEVICE_VERSION (0x8004)
|
||||
#define ICSNEO_MESSAGE_TYPE_MAIN51 (0x8005)
|
||||
#define ICSNEO_MESSAGE_TYPE_FLEXRAY_CONTROL (0x8006)
|
||||
|
||||
#endif // __ICSNEOC_H_
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user