correctly send out seasmart only if NMEA out is not enabled on channel

This commit is contained in:
wellenvogel 2022-01-12 18:55:08 +01:00
parent ff1c6432af
commit 74064fb664
3 changed files with 24 additions and 12 deletions

View File

@ -128,9 +128,11 @@ void GwChannel::updateCounter(const char *msg, bool out)
} }
} }
bool GwChannel::canSendOut(const char *buffer){ bool GwChannel::canSendOut(const char *buffer, bool isSeasmart){
if (! enabled || ! impl) return false; if (! enabled || ! impl) return false;
if (! NMEAout || readActisense) return false; if (readActisense) return false;
if (! isSeasmart && ! NMEAout) return false;
if (isSeasmart && ! seaSmartOut) return false;
if (writeFilter && ! writeFilter->canPass(buffer)) return false; if (writeFilter && ! writeFilter->canPass(buffer)) return false;
return true; return true;
} }
@ -177,9 +179,9 @@ void GwChannel::readMessages(GwChannel::NMEA0183Handler handler){
receiver->setHandler(handler); receiver->setHandler(handler);
impl->readMessages(receiver); impl->readMessages(receiver);
} }
void GwChannel::sendToClients(const char *buffer, int sourceId){ void GwChannel::sendToClients(const char *buffer, int sourceId, bool isSeasmart){
if (! impl) return; if (! impl) return;
if (canSendOut(buffer)){ if (canSendOut(buffer,isSeasmart)){
if(impl->sendToClients(buffer,sourceId)){ if(impl->sendToClients(buffer,sourceId)){
updateCounter(buffer,true); updateCounter(buffer,true);
} }

View File

@ -56,7 +56,7 @@ class GwChannel{
} }
bool isEnabled(){return enabled;} bool isEnabled(){return enabled;}
bool shouldRead(){return enabled && NMEAin;} bool shouldRead(){return enabled && NMEAin;}
bool canSendOut(const char *buffer); bool canSendOut(const char *buffer, bool isSeasmart);
bool canReceive(const char *buffer); bool canReceive(const char *buffer);
bool sendSeaSmart(){ return seaSmartOut;} bool sendSeaSmart(){ return seaSmartOut;}
bool sendToN2K(){return toN2k;} bool sendToN2K(){return toN2k;}
@ -67,7 +67,7 @@ class GwChannel{
void loop(bool handleRead, bool handleWrite); void loop(bool handleRead, bool handleWrite);
typedef std::function<void(const char *buffer, int sourceid)> NMEA0183Handler; typedef std::function<void(const char *buffer, int sourceid)> NMEA0183Handler;
void readMessages(NMEA0183Handler handler); void readMessages(NMEA0183Handler handler);
void sendToClients(const char *buffer, int sourceId); void sendToClients(const char *buffer, int sourceId, bool isSeasmart=false);
typedef std::function<void(const tN2kMsg &msg, int sourceId)> N2kHandler ; typedef std::function<void(const tN2kMsg &msg, int sourceId)> N2kHandler ;
void parseActisense(N2kHandler handler); void parseActisense(N2kHandler handler);
void sendActisense(const tN2kMsg &msg, int sourceId); void sendActisense(const tN2kMsg &msg, int sourceId);

View File

@ -177,18 +177,24 @@ void handleN2kMessage(const tN2kMsg &n2kMsg,int sourceId, bool isConverted=false
if (sourceId == N2K_CHANNEL_ID){ if (sourceId == N2K_CHANNEL_ID){
countNMEA2KIn.add(n2kMsg.PGN); countNMEA2KIn.add(n2kMsg.PGN);
} }
char *buf=new char[MAX_NMEA2000_MESSAGE_SEASMART_SIZE]; char *buf=new char[MAX_NMEA2000_MESSAGE_SEASMART_SIZE+3];
std::unique_ptr<char> bufDel(buf); std::unique_ptr<char> bufDel(buf);
bool messageCreated=false; bool messageCreated=false;
channels.allChannels([&](GwChannel *c){ channels.allChannels([&](GwChannel *c){
if (c->sendSeaSmart()){ if (c->sendSeaSmart()){
if (! messageCreated){ if (! messageCreated){
if (N2kToSeasmart(n2kMsg, millis(), buf, MAX_NMEA2000_MESSAGE_SEASMART_SIZE) != 0) { size_t len;
if ((len=N2kToSeasmart(n2kMsg, millis(), buf, MAX_NMEA2000_MESSAGE_SEASMART_SIZE)) != 0) {
buf[len]=0x0d;
len++;
buf[len]=0x0a;
len++;
buf[len]=0;
messageCreated=true; messageCreated=true;
} }
} }
if (messageCreated){ if (messageCreated){
c->sendToClients(buf,sourceId); c->sendToClients(buf,sourceId,true);
} }
} }
}); });
@ -221,7 +227,7 @@ void SendNMEA0183Message(const tNMEA0183Msg &NMEA0183Msg, int sourceId,bool conv
buf[len+1]=0x0a; buf[len+1]=0x0a;
buf[len+2]=0; buf[len+2]=0;
channels.allChannels([&](GwChannel *c){ channels.allChannels([&](GwChannel *c){
c->sendToClients(buf,sourceId); c->sendToClients(buf,sourceId,false);
}); });
} }
@ -785,12 +791,16 @@ void loop() {
//read channels //read channels
channels.allChannels([](GwChannel *c){ channels.allChannels([](GwChannel *c){
c->readMessages([&](const char * buffer, int sourceId){ c->readMessages([&](const char * buffer, int sourceId){
bool isSeasmart=false;
if (strlen(buffer) > 6 && strncmp(buffer,"$PCDIN",6) == 0){
isSeasmart=true;
}
channels.allChannels([&](GwChannel *oc){ channels.allChannels([&](GwChannel *oc){
oc->sendToClients(buffer,sourceId); oc->sendToClients(buffer,sourceId,isSeasmart);
oc->loop(false,true); oc->loop(false,true);
}); });
if (c->sendToN2K()){ if (c->sendToN2K()){
if (strlen(buffer) > 6 && strncmp(buffer,"$PCDIN",6) == 0){ if (isSeasmart){
tN2kMsg n2kMsg; tN2kMsg n2kMsg;
uint32_t timestamp; uint32_t timestamp;
if (SeasmartToN2k(buffer,timestamp,n2kMsg)){ if (SeasmartToN2k(buffer,timestamp,n2kMsg)){