mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Communication uses instantiated Packetizers and Decoders now
This commit is contained in:
@@ -138,15 +138,13 @@ std::shared_ptr<Message> Communication::waitForMessageSync(MessageFilter f, std:
|
||||
|
||||
void Communication::readTask() {
|
||||
std::vector<uint8_t> readBytes;
|
||||
Packetizer packetizer;
|
||||
MessageDecoder decoder;
|
||||
|
||||
while(!closing) {
|
||||
readBytes.clear();
|
||||
if(impl->readWait(readBytes)) {
|
||||
if(packetizer.input(readBytes)) {
|
||||
for(auto& packet : packetizer.output()) {
|
||||
auto msg = decoder.decodePacket(packet);
|
||||
if(packetizer->input(readBytes)) {
|
||||
for(auto& packet : packetizer->output()) {
|
||||
auto msg = decoder->decodePacket(packet);
|
||||
for(auto& cb : messageCallbacks) { // We might have closed while reading or processing
|
||||
if(!closing) {
|
||||
cb.second.callIfMatch(msg);
|
||||
|
||||
@@ -18,7 +18,7 @@ class Communication {
|
||||
public:
|
||||
static uint8_t ICSChecksum(const std::vector<uint8_t>& data);
|
||||
|
||||
Communication(std::shared_ptr<ICommunication> com) : impl(com) {}
|
||||
Communication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<MessageDecoder> md) : impl(com), packetizer(p), decoder(md) {}
|
||||
virtual ~Communication() { close(); }
|
||||
|
||||
bool open();
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
|
||||
void setAlign16Bit(bool enable) { align16bit = enable; }
|
||||
|
||||
std::shared_ptr<Packetizer> packetizer;
|
||||
std::shared_ptr<MessageDecoder> decoder;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<ICommunication> impl;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace icsneo {
|
||||
|
||||
class MultiChannelCommunication : public Communication {
|
||||
public:
|
||||
MultiChannelCommunication(std::shared_ptr<ICommunication> com) : Communication(com) {}
|
||||
MultiChannelCommunication(std::shared_ptr<ICommunication> com, std::shared_ptr<Packetizer> p, std::shared_ptr<MessageDecoder> md) : Communication(com, p, md) {}
|
||||
void spawnThreads();
|
||||
void joinThreads();
|
||||
bool sendCommand(Command cmd, std::vector<uint8_t> arguments);
|
||||
|
||||
@@ -32,8 +32,6 @@ void MultiChannelCommunication::readTask() {
|
||||
std::deque<uint8_t> usbReadFifo;
|
||||
std::vector<uint8_t> readBytes;
|
||||
std::vector<uint8_t> payloadBytes;
|
||||
Packetizer packetizer;
|
||||
MessageDecoder decoder;
|
||||
|
||||
while(!closing) {
|
||||
if(readMore) {
|
||||
@@ -108,9 +106,9 @@ void MultiChannelCommunication::readTask() {
|
||||
usbReadFifo.pop_front();
|
||||
}
|
||||
|
||||
if(packetizer.input(payloadBytes)) {
|
||||
for(auto& packet : packetizer.output()) {
|
||||
auto msg = decoder.decodePacket(packet);
|
||||
if(packetizer->input(payloadBytes)) {
|
||||
for(auto& packet : packetizer->output()) {
|
||||
auto msg = decoder->decodePacket(packet);
|
||||
for(auto& cb : messageCallbacks) { // We might have closed while reading or processing
|
||||
if(!closing) {
|
||||
cb.second.callIfMatch(msg);
|
||||
|
||||
Reference in New Issue
Block a user