mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-16 07:23:07 +01:00
intermediate: introduce an abstract channel
This commit is contained in:
75
lib/channel/GwChannel.h
Normal file
75
lib/channel/GwChannel.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include "GwChannelInterface.h"
|
||||
#include "GwConfigItem.h"
|
||||
#include "GwLog.h"
|
||||
#include "GWConfig.h"
|
||||
#include "GwCounter.h"
|
||||
#include "GwJsonDocument.h"
|
||||
#include <N2kMsg.h>
|
||||
#include <functional>
|
||||
|
||||
class GwChannelMessageReceiver;
|
||||
class tActisenseReader;
|
||||
class GwChannel{
|
||||
bool enabled=false;
|
||||
bool NMEAout=false;
|
||||
bool NMEAin=false;
|
||||
GwNmeaFilter* readFilter=NULL;
|
||||
GwNmeaFilter* writeFilter=NULL;
|
||||
bool seaSmartOut=false;
|
||||
bool toN2k=false;
|
||||
bool readActisense=false;
|
||||
bool writeActisense=false;
|
||||
GwLog *logger;
|
||||
String name;
|
||||
GwCounter<String> *countIn=NULL;
|
||||
GwCounter<String> *countOut=NULL;
|
||||
GwChannelInterface *impl;
|
||||
int sourceId=0;
|
||||
GwChannelMessageReceiver *receiver=NULL;
|
||||
tActisenseReader *actisenseReader=NULL;
|
||||
Stream *channelStream=NULL;
|
||||
void updateCounter(const char *msg, bool out);
|
||||
public:
|
||||
GwChannel(
|
||||
GwLog *logger,
|
||||
String name,
|
||||
int sourceId);
|
||||
void begin(
|
||||
bool enabled,
|
||||
bool nmeaOut,
|
||||
bool nmeaIn,
|
||||
String readFilter,
|
||||
String writeFilter,
|
||||
bool seaSmartOut,
|
||||
bool toN2k,
|
||||
bool readActisense=false,
|
||||
bool writeActisense=false
|
||||
);
|
||||
|
||||
void setImpl(GwChannelInterface *impl);
|
||||
|
||||
void enable(bool enabled){
|
||||
this->enabled=enabled;
|
||||
}
|
||||
bool isEnabled(){return enabled;}
|
||||
bool shouldRead(){return enabled && NMEAin;}
|
||||
bool canSendOut(unsigned long pgn);
|
||||
bool canReceive(unsigned long pgn);
|
||||
bool canSendOut(const char *buffer);
|
||||
bool canReceive(const char *buffer);
|
||||
bool sendSeaSmart(){ return seaSmartOut;}
|
||||
bool sendToN2K(){return toN2k;}
|
||||
int getJsonSize();
|
||||
void toJson(GwJsonDocument &doc);
|
||||
String toString();
|
||||
|
||||
void loop(bool handleRead, bool handleWrite);
|
||||
typedef std::function<void(const char *buffer, int sourceid)> NMEA0183Handler;
|
||||
void readMessages(NMEA0183Handler handler);
|
||||
void sendToClients(const char *buffer, int sourceId);
|
||||
typedef std::function<void(const tN2kMsg &msg, int sourceId)> N2kHandler ;
|
||||
void parseActisense(N2kHandler handler);
|
||||
void sendActisense(const tN2kMsg &msg);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user