1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-14 06:23:07 +01:00

intermediate: multiple groves

This commit is contained in:
andreas
2024-03-19 20:54:32 +01:00
parent 59a80fcc9a
commit 746c9e3da0
5 changed files with 107 additions and 86 deletions

View File

@@ -4,16 +4,12 @@
using SerInitFunction=std::function<void(GwChannelList *)>;
std::vector<SerInitFunction> initFunctions;
#define CFG_EXP(ser) GwChannelList::ser
#define CFG_SERIAL(ser,rx,tx,mode) \
__MSG("serial config " __STR(ser) " rx=" __STR(rx) ", tx=" __STR(tx) ",mode=" __STR(mode)); \
static GwInitializer<SerInitFunction> _ ## name ## _init( \
initFunctions,[](GwChannelList *cl){cl->addSerial(CFG_EXP(ser),rx,tx,mode);});
#define CFG_SERIAL(id,ser,rx,tx,mode) \
__MSG("serial config " #id __XSTR(ser) "(" #ser ")" " rx=" __XSTR(rx) ", tx=" __XSTR(tx) ",mode=" __STR(mode)); \
static GwInitializer<SerInitFunction> __serial ## id ## _init \
(initFunctions,[](GwChannelList *cl){cl->addSerial(ser,rx,tx,mode);});
//check for duplicate groove usages
#define __GR_EXP(GROOVE) __groveuse_ ## GROOVE
#define GROVE_USE(USER) \
__MSG("grove " __STR(USER) " used by " #USER) \
static int __GR_EXP(USER) =1;
#define GW_PINDEFS
#include "GwHardware.h"
#include "GwSocketServer.h"
#include "GwSerial.h"
@@ -115,16 +111,16 @@ static SerialParam *getSerialParam(int id){
}
return nullptr;
}
void GwChannelList::addSerial(const String &name, int rx, int tx, int type){
if (name == serial){
void GwChannelList::addSerial(int id, int rx, int tx, int type){
if (id == 1){
addSerial(&Serial1,SERIAL1_CHANNEL_ID,type,rx,tx);
return;
}
if (name == serial2){
if (id == 2){
addSerial(&Serial2,SERIAL2_CHANNEL_ID,type,rx,tx);
return;
}
LOG_DEBUG(GwLog::ERROR,"invalid serial config")
LOG_DEBUG(GwLog::ERROR,"invalid serial config with id %d",id);
}
void GwChannelList::addSerial(HardwareSerial *stream,int id,int type,int rx,int tx){
const char *mode=nullptr;

View File

@@ -33,9 +33,7 @@ class GwChannelList{
void addSerial(HardwareSerial *stream,int id,const String &mode,int rx,int tx);
void addSerial(HardwareSerial *stream,int id,int type,int rx,int tx);
public:
static constexpr const char* serial="serial";
static constexpr const char* serial2="serial2";
void addSerial(const String &name, int rx, int tx, int type);
void addSerial(int id, int rx, int tx, int type);
GwChannelList(GwLog *logger, GwConfigHandler *config);
typedef std::function<void(GwChannel *)> ChannelAction;
void allChannels(ChannelAction action);