Skip to content

Commit

Permalink
correctly send out seasmart only if NMEA out is not enabled on channel
Browse files Browse the repository at this point in the history
  • Loading branch information
wellenvogel committed Jan 12, 2022
1 parent ff1c643 commit 74064fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
10 changes: 6 additions & 4 deletions lib/channel/GwChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (! 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;
return true;
}
Expand Down Expand Up @@ -177,9 +179,9 @@ void GwChannel::readMessages(GwChannel::NMEA0183Handler handler){
receiver->setHandler(handler);
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 (canSendOut(buffer)){
if (canSendOut(buffer,isSeasmart)){
if(impl->sendToClients(buffer,sourceId)){
updateCounter(buffer,true);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/channel/GwChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GwChannel{
}
bool isEnabled(){return enabled;}
bool shouldRead(){return enabled && NMEAin;}
bool canSendOut(const char *buffer);
bool canSendOut(const char *buffer, bool isSeasmart);
bool canReceive(const char *buffer);
bool sendSeaSmart(){ return seaSmartOut;}
bool sendToN2K(){return toN2k;}
Expand All @@ -67,7 +67,7 @@ class GwChannel{
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);
void sendToClients(const char *buffer, int sourceId, bool isSeasmart=false);
typedef std::function<void(const tN2kMsg &msg, int sourceId)> N2kHandler ;
void parseActisense(N2kHandler handler);
void sendActisense(const tN2kMsg &msg, int sourceId);
Expand Down
22 changes: 16 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,24 @@ void handleN2kMessage(const tN2kMsg &n2kMsg,int sourceId, bool isConverted=false
if (sourceId == N2K_CHANNEL_ID){
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);
bool messageCreated=false;
channels.allChannels([&](GwChannel *c){
if (c->sendSeaSmart()){
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;
}
}
if (messageCreated){
c->sendToClients(buf,sourceId);
c->sendToClients(buf,sourceId,true);
}
}
});
Expand Down Expand Up @@ -221,7 +227,7 @@ void SendNMEA0183Message(const tNMEA0183Msg &NMEA0183Msg, int sourceId,bool conv
buf[len+1]=0x0a;
buf[len+2]=0;
channels.allChannels([&](GwChannel *c){
c->sendToClients(buf,sourceId);
c->sendToClients(buf,sourceId,false);
});
}

Expand Down Expand Up @@ -785,12 +791,16 @@ void loop() {
//read channels
channels.allChannels([](GwChannel *c){
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){
oc->sendToClients(buffer,sourceId);
oc->sendToClients(buffer,sourceId,isSeasmart);
oc->loop(false,true);
});
if (c->sendToN2K()){
if (strlen(buffer) > 6 && strncmp(buffer,"$PCDIN",6) == 0){
if (isSeasmart){
tN2kMsg n2kMsg;
uint32_t timestamp;
if (SeasmartToN2k(buffer,timestamp,n2kMsg)){
Expand Down

0 comments on commit 74064fb

Please sign in to comment.