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

move serial channel mode to serial channel type (integer)

This commit is contained in:
andreas
2023-08-31 22:03:23 +02:00
parent f36dd37b8b
commit 8c7540d956
4 changed files with 59 additions and 25 deletions

View File

@@ -102,6 +102,29 @@ static SerialParam *getSerialParam(int id){
return nullptr;
}
void GwChannelList:: addSerial(HardwareSerial *stream,int id,int type,int rx,int tx){
const char *mode=nullptr;
switch (type)
{
case GWSERIAL_TYPE_UNI:
mode="UNI";
break;
case GWSERIAL_TYPE_BI:
mode="BI";
break;
case GWSERIAL_TYPE_RX:
mode="RX";
break;
case GWSERIAL_TYPE_TX:
mode="TX";
break;
}
if (mode == nullptr) {
LOG_DEBUG(GwLog::ERROR,"unknown serial type %d",type);
return;
}
addSerial(stream,id,mode,rx,tx);
}
void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &mode,int rx,int tx){
SerialParam *param=getSerialParam(id);
if (param == nullptr){
@@ -112,6 +135,7 @@ void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &
logger->logDebug(GwLog::ERROR,"useless config for serial %d: both rx/tx undefined");
return;
}
modes[id]=String(mode);
bool canRead=false;
bool canWrite=false;
if (mode == "BI"){
@@ -155,6 +179,7 @@ void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &
LOG_DEBUG(GwLog::LOG, "%s", channel->toString().c_str());
theChannels.push_back(channel);
}
void GwChannelList::begin(bool fallbackSerial){
LOG_DEBUG(GwLog::DEBUG,"GwChannelList::begin");
GwChannel *channel=NULL;
@@ -205,8 +230,12 @@ void GwChannelList::begin(bool fallbackSerial){
#ifndef GWSERIAL_RX
#define GWSERIAL_RX -1
#endif
#ifdef GWSERIAL_MODE
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_MODE,GWSERIAL_RX,GWSERIAL_TX);
#ifdef GWSERIAL_TYPE
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_TYPE,GWSERIAL_RX,GWSERIAL_TX);
#else
#ifdef GWSERIAL_MODE
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_MODE,GWSERIAL_RX,GWSERIAL_TX);
#endif
#endif
//serial 2
#ifndef GWSERIAL2_TX
@@ -215,8 +244,12 @@ void GwChannelList::begin(bool fallbackSerial){
#ifndef GWSERIAL2_RX
#define GWSERIAL2_RX -1
#endif
#ifdef GWSERIAL2_MODE
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_MODE,GWSERIAL2_RX,GWSERIAL2_TX);
#ifdef GWSERIAL2_TYPE
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_TYPE,GWSERIAL2_RX,GWSERIAL2_TX);
#else
#ifdef GWSERIAL2_MODE
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_MODE,GWSERIAL2_RX,GWSERIAL2_TX);
#endif
#endif
//tcp client
bool tclEnabled=config->getBool(config->tclEnabled);
@@ -245,6 +278,11 @@ void GwChannelList::begin(bool fallbackSerial){
LOG_DEBUG(GwLog::LOG,"%s",channel->toString().c_str());
logger->flush();
}
String GwChannelList::getMode(int id){
auto it=modes.find(id);
if (it != modes.end()) return it->second;
return "UNKNOWN";
}
int GwChannelList::getJsonSize(){
int rt=0;
allChannels([&](GwChannel *c){

View File

@@ -1,6 +1,7 @@
#pragma once
#include <functional>
#include <vector>
#include <map>
#include <WString.h>
#include "GwChannel.h"
#include "GwLog.h"
@@ -26,10 +27,11 @@ class GwChannelList{
GwConfigHandler *config;
typedef std::vector<GwChannel *> ChannelList;
ChannelList theChannels;
std::map<int,String> modes;
GwSocketServer *sockets;
GwTcpClient *client;
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:
GwChannelList(GwLog *logger, GwConfigHandler *config);
typedef std::function<void(GwChannel *)> ChannelAction;
@@ -42,6 +44,6 @@ class GwChannelList{
//single channel
GwChannel *getChannelById(int sourceId);
void fillStatus(GwApi::Status &status);
String getMode(int id);
};