Testing the encoder for sending more complex messages

This commit is contained in:
Paul Hollinsky
2018-10-03 14:33:30 -04:00
parent 590a99d995
commit dffae23e54
13 changed files with 78 additions and 37 deletions
+7 -1
View File
@@ -8,6 +8,7 @@
#include "communication/message/callback/include/messagecallback.h"
#include "communication/message/include/serialnumbermessage.h"
#include "communication/include/packetizer.h"
#include "communication/include/encoder.h"
#include "communication/include/decoder.h"
#include <memory>
#include <vector>
@@ -20,7 +21,11 @@ namespace icsneo {
class Communication {
public:
Communication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<Decoder> md) : packetizer(p), decoder(md), impl(com) {}
Communication(
std::shared_ptr<ICommunication> com,
std::shared_ptr<Packetizer> p,
std::shared_ptr<Encoder> e,
std::shared_ptr<Decoder> md) : packetizer(p), encoder(e), decoder(md), impl(com) {}
virtual ~Communication() { close(); }
bool open();
@@ -43,6 +48,7 @@ public:
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<Encoder> encoder;
std::shared_ptr<Decoder> decoder;
protected:
+5
View File
@@ -4,7 +4,9 @@
#include "communication/message/include/message.h"
#include "communication/message/include/canmessage.h"
#include "communication/include/packet.h"
#include "communication/include/command.h"
#include "communication/include/network.h"
#include "communication/include/packetizer.h"
#include <queue>
#include <vector>
#include <memory>
@@ -15,11 +17,14 @@ namespace icsneo {
class Encoder {
public:
Encoder(std::shared_ptr<Packetizer> packetizerInstance) : packetizer(packetizerInstance) {}
std::vector<uint8_t> encode(const std::shared_ptr<Message>& message);
std::vector<uint8_t> encode(Command cmd, bool boolean) { return encode(cmd, std::vector<uint8_t>({ (uint8_t)boolean })); }
std::vector<uint8_t> encode(Command cmd, std::vector<uint8_t> arguments = {});
private:
std::shared_ptr<Packetizer> packetizer;
typedef uint16_t icscm_bitfield;
struct HardwareCANPacket {
struct {
@@ -4,12 +4,17 @@
#include "communication/include/communication.h"
#include "communication/include/icommunication.h"
#include "communication/include/command.h"
#include "communication/include/encoder.h"
namespace icsneo {
class MultiChannelCommunication : public Communication {
public:
MultiChannelCommunication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<Decoder> md) : Communication(com, p, md) {}
MultiChannelCommunication(
std::shared_ptr<ICommunication> com,
std::shared_ptr<Packetizer> p,
std::shared_ptr<Encoder> e,
std::shared_ptr<Decoder> md) : Communication(com, p, e, md) {}
void spawnThreads() override;
void joinThreads() override;
bool sendPacket(std::vector<uint8_t>& bytes) override;
+1 -1
View File
@@ -11,7 +11,7 @@ namespace icsneo {
class Packetizer {
public:
static uint8_t ICSChecksum(const std::vector<uint8_t>& data);
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data, bool checksum = true);
std::vector<uint8_t>& packetWrap(std::vector<uint8_t>& data, bool shortFormat);
bool input(const std::vector<uint8_t>& bytes);
std::vector<std::shared_ptr<Packet>> output();