Refactor MessageDecoder to Decoder

pull/4/head
Paul Hollinsky 2018-09-25 18:00:16 -04:00
parent 69773d6537
commit 9f20d70102
20 changed files with 301 additions and 301 deletions

View File

@ -41,7 +41,7 @@ endif()
set(COMMON_SRC set(COMMON_SRC
communication/message/neomessage.cpp communication/message/neomessage.cpp
communication/messagedecoder.cpp communication/decoder.cpp
communication/packetizer.cpp communication/packetizer.cpp
communication/multichannelcommunication.cpp communication/multichannelcommunication.cpp
communication/communication.cpp communication/communication.cpp

View File

@ -7,7 +7,7 @@
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
#include "communication/include/command.h" #include "communication/include/command.h"
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
#include "communication/include/packetizer.h" #include "communication/include/packetizer.h"
#include "communication/message/include/serialnumbermessage.h" #include "communication/message/include/serialnumbermessage.h"
#include "communication/message/filter/include/main51messagefilter.h" #include "communication/message/filter/include/main51messagefilter.h"

View File

@ -1,4 +1,4 @@
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
#include "communication/include/communication.h" #include "communication/include/communication.h"
#include "communication/message/include/serialnumbermessage.h" #include "communication/message/include/serialnumbermessage.h"
#include "communication/include/command.h" #include "communication/include/command.h"
@ -7,14 +7,14 @@
using namespace icsneo; using namespace icsneo;
uint64_t MessageDecoder::GetUInt64FromLEBytes(uint8_t* bytes) { uint64_t Decoder::GetUInt64FromLEBytes(uint8_t* bytes) {
uint64_t ret = 0; uint64_t ret = 0;
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
ret |= (bytes[i] << (i * 8)); ret |= (bytes[i] << (i * 8));
return ret; return ret;
} }
std::shared_ptr<Message> MessageDecoder::decodePacket(const std::shared_ptr<Packet>& packet) { std::shared_ptr<Message> Decoder::decodePacket(const std::shared_ptr<Packet>& packet) {
switch(packet->network.getType()) { switch(packet->network.getType()) {
case Network::Type::CAN: { case Network::Type::CAN: {
if(packet->data.size() < 24) if(packet->data.size() < 24)

View File

@ -8,7 +8,7 @@
#include "communication/message/callback/include/messagecallback.h" #include "communication/message/callback/include/messagecallback.h"
#include "communication/message/include/serialnumbermessage.h" #include "communication/message/include/serialnumbermessage.h"
#include "communication/include/packetizer.h" #include "communication/include/packetizer.h"
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <atomic> #include <atomic>
@ -20,7 +20,7 @@ namespace icsneo {
class Communication { class Communication {
public: public:
Communication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<MessageDecoder> md) : impl(com), packetizer(p), decoder(md) {} Communication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<Decoder> md) : impl(com), packetizer(p), decoder(md) {}
virtual ~Communication() { close(); } virtual ~Communication() { close(); }
bool open(); bool open();
@ -43,7 +43,7 @@ public:
std::shared_ptr<Message> waitForMessageSync(std::shared_ptr<MessageFilter> f, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); std::shared_ptr<Message> waitForMessageSync(std::shared_ptr<MessageFilter> f, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
std::shared_ptr<Packetizer> packetizer; std::shared_ptr<Packetizer> packetizer;
std::shared_ptr<MessageDecoder> decoder; std::shared_ptr<Decoder> decoder;
protected: protected:
std::shared_ptr<ICommunication> impl; std::shared_ptr<ICommunication> impl;

View File

@ -1,5 +1,5 @@
#ifndef __MESSAGEDECODER_H_ #ifndef __DECODER_H_
#define __MESSAGEDECODER_H_ #define __DECODER_H_
#include "communication/message/include/message.h" #include "communication/message/include/message.h"
#include "communication/message/include/canmessage.h" #include "communication/message/include/canmessage.h"
@ -14,7 +14,7 @@
namespace icsneo { namespace icsneo {
class MessageDecoder { class Decoder {
public: public:
static uint64_t GetUInt64FromLEBytes(uint8_t* bytes); static uint64_t GetUInt64FromLEBytes(uint8_t* bytes);
std::shared_ptr<Message> decodePacket(const std::shared_ptr<Packet>& message); std::shared_ptr<Message> decodePacket(const std::shared_ptr<Packet>& message);

View File

@ -9,7 +9,7 @@ namespace icsneo {
class MultiChannelCommunication : public Communication { class MultiChannelCommunication : public Communication {
public: public:
MultiChannelCommunication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<MessageDecoder> md) : Communication(com, p, md) {} MultiChannelCommunication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<Decoder> md) : Communication(com, p, md) {}
void spawnThreads(); void spawnThreads();
void joinThreads(); void joinThreads();
bool sendCommand(Command cmd, std::vector<uint8_t> arguments); bool sendCommand(Command cmd, std::vector<uint8_t> arguments);

View File

@ -1,6 +1,6 @@
#include "communication/include/multichannelcommunication.h" #include "communication/include/multichannelcommunication.h"
#include "communication/include/command.h" #include "communication/include/command.h"
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
#include "communication/include/packetizer.h" #include "communication/include/packetizer.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>

View File

@ -8,7 +8,7 @@
#include "device/include/idevicesettings.h" #include "device/include/idevicesettings.h"
#include "communication/include/communication.h" #include "communication/include/communication.h"
#include "communication/include/packetizer.h" #include "communication/include/packetizer.h"
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
#include "third-party/concurrentqueue/concurrentqueue.h" #include "third-party/concurrentqueue/concurrentqueue.h"
namespace icsneo { namespace icsneo {

View File

@ -14,7 +14,7 @@ public:
NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) { NeoOBD2PRO(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<STM32>(getWritableNeoDevice()); auto transport = std::make_shared<STM32>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -14,7 +14,7 @@ public:
NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) { NeoOBD2SIM(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<STM32>(getWritableNeoDevice()); auto transport = std::make_shared<STM32>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -13,7 +13,7 @@ public:
NeoVIFIRE(neodevice_t neodevice) : Device(neodevice) { NeoVIFIRE(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice()); auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -13,7 +13,7 @@ public:
NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) { NeoVIFIRE2ETH(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
auto transport = std::make_shared<PCAP>(getWritableNeoDevice()); auto transport = std::make_shared<PCAP>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }

View File

@ -12,7 +12,7 @@ public:
NeoVIFIRE2USB(neodevice_t neodevice) : NeoVIFIRE2(neodevice) { NeoVIFIRE2USB(neodevice_t neodevice) : NeoVIFIRE2(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice()); auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
productId = PRODUCT_ID; productId = PRODUCT_ID;
} }

View File

@ -12,7 +12,7 @@ public:
Plasion(neodevice_t neodevice) : Device(neodevice) { Plasion(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice()); auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<MultiChannelCommunication>(transport, packetizer, decoder); com = std::make_shared<MultiChannelCommunication>(transport, packetizer, decoder);
} }
}; };

View File

@ -4,7 +4,7 @@
#include "device/include/device.h" #include "device/include/device.h"
#include "platform/include/pcap.h" #include "platform/include/pcap.h"
#include "communication/include/packetizer.h" #include "communication/include/packetizer.h"
#include "communication/include/messagedecoder.h" #include "communication/include/decoder.h"
namespace icsneo { namespace icsneo {
@ -18,7 +18,7 @@ public:
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
packetizer->disableChecksum = true; packetizer->disableChecksum = true;
packetizer->align16bit = false; packetizer->align16bit = false;
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -14,7 +14,7 @@ public:
RADStar2(neodevice_t neodevice) : Device(neodevice) { RADStar2(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice()); auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -16,7 +16,7 @@ public:
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
packetizer->disableChecksum = true; packetizer->disableChecksum = true;
packetizer->align16bit = false; packetizer->align16bit = false;
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -13,7 +13,7 @@ public:
ValueCAN3(neodevice_t neodevice) : Device(neodevice) { ValueCAN3(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<FTDI>(getWritableNeoDevice()); auto transport = std::make_shared<FTDI>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -14,7 +14,7 @@ public:
ValueCAN4(neodevice_t neodevice) : Device(neodevice) { ValueCAN4(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<STM32>(getWritableNeoDevice()); auto transport = std::make_shared<STM32>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;

View File

@ -14,7 +14,7 @@ public:
VividCAN(neodevice_t neodevice) : Device(neodevice) { VividCAN(neodevice_t neodevice) : Device(neodevice) {
auto transport = std::make_shared<STM32>(getWritableNeoDevice()); auto transport = std::make_shared<STM32>(getWritableNeoDevice());
auto packetizer = std::make_shared<Packetizer>(); auto packetizer = std::make_shared<Packetizer>();
auto decoder = std::make_shared<MessageDecoder>(); auto decoder = std::make_shared<Decoder>();
com = std::make_shared<Communication>(transport, packetizer, decoder); com = std::make_shared<Communication>(transport, packetizer, decoder);
setProductName(PRODUCT_NAME); setProductName(PRODUCT_NAME);
productId = PRODUCT_ID; productId = PRODUCT_ID;