correctly send out seasmart only if NMEA out is not enabled on channel
This commit is contained in:
parent
ff1c6432af
commit
74064fb664
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;}
|
||||
|
@ -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);
|
||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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)){
|
||||
|
|
Loading…
Reference in New Issue