Legacy API can receive CAN now

This commit is contained in:
Paul Hollinsky
2018-10-08 21:43:32 -04:00
parent b3471890eb
commit ba9813021e
11 changed files with 142 additions and 42 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ bool ICommunication::read(std::vector<uint8_t>& bytes, size_t limit) {
size_t actuallyRead = readQueue.try_dequeue_bulk(bytes.data(), limit);
bytes.resize(actuallyRead);
if(bytes.size() > actuallyRead)
bytes.resize(actuallyRead);
return true;
}
+11 -1
View File
@@ -112,16 +112,19 @@ public:
LSFTCAN2 = 99,
HW_COM_Latency_Test = 512,
Device_Status = 513,
Any = 0xfffe, // Never actually set as type, but used as flag for filtering
Invalid = 0xffff
};
enum class Type {
Invalid,
Internal, // Used for statuses that don't actually need to be transferred to the client application
CAN,
LIN,
FlexRay,
MOST,
Ethernet,
Other,
Invalid
Any // Never actually set as type, but used as flag for filtering
};
static const char* GetTypeString(Type type) {
switch(type) {
@@ -135,6 +138,8 @@ public:
return "MOST";
case Type::Other:
return "Other";
case Type::Internal:
return "Internal";
case Type::Invalid:
default:
return "Invalid Type";
@@ -173,7 +178,12 @@ public:
case NetID::MOST50:
case NetID::MOST150:
return Type::MOST;
case NetID::RED:
case NetID::Reset_Status:
case NetID::Device_Status:
return Type::Internal;
case NetID::Invalid:
case NetID::Any:
return Type::Invalid;
default:
return Type::Other;
@@ -9,14 +9,14 @@ namespace icsneo {
class MessageFilter {
public:
MessageFilter() : matchAny(true) {}
MessageFilter() {}
MessageFilter(Network::Type type) : type(type) {}
MessageFilter(Network::NetID netid) : netid(netid) {}
virtual ~MessageFilter() {}
// 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(matchAny)
return true;
if(!matchType(message->network.getType()))
return false;
if(!matchNetID(message->network.getNetID()))
@@ -25,18 +25,16 @@ public:
}
private:
bool matchAny = false;
Network::Type type = Network::Type::Invalid; // Matching a type of invalid will match any
Network::Type type = Network::Type::Any;
bool matchType(Network::Type mtype) const {
if(type == Network::Type::Invalid)
if(type == Network::Type::Any && (mtype != Network::Type::Internal || includeInternalInAny))
return true;
return type == mtype;
}
Network::NetID netid = Network::NetID::Invalid; // Matching a netid of invalid will match any
Network::NetID netid = Network::NetID::Any;
bool matchNetID(Network::NetID mnetid) const {
if(netid == Network::NetID::Invalid)
if(netid == Network::NetID::Any)
return true;
return netid == mnetid;
}