#107: correctly handle DBT,DBS,DBK

This commit is contained in:
andreas 2025-04-22 19:35:57 +02:00
parent c55bcc1f94
commit 38d370dcfb
4 changed files with 27 additions and 18 deletions

Binary file not shown.

Binary file not shown.

View File

@ -638,8 +638,8 @@ private:
for (int i=0;i< 3;i++){
if (msg.FieldLen(0)>0){
Depth=atof(msg.Field(0));
char dt=msg.Field(i+1)[0];
switch(dt){
char du=msg.Field(i+1)[0];
switch(du){
case 'f':
Depth=Depth/mToFeet;
break;
@ -662,8 +662,9 @@ private:
//we can only send if we have a valid depth beloww tranducer
//to compute the offset
if (! boatData->DBT->isValid()) return;
double offset=Depth-boatData->DBT->getData();
if (offset >= 0 && dt == DBT){
double dbs=boatData->DBT->getData();
double offset=Depth-dbs;
if (offset >= 0 && dt == DBK){
logger->logDebug(GwLog::DEBUG, "strange DBK - more depth then transducer %s", msg.line);
return;
}
@ -675,8 +676,8 @@ private:
if (! boatData->DBS->update(Depth,msg.sourceId)) return;
}
tN2kMsg n2kMsg;
SetN2kWaterDepth(n2kMsg,1,Depth,offset);
send(n2kMsg,msg.sourceId,(n2kMsg.PGN)+String((offset != N2kDoubleNA)?1:0));
SetN2kWaterDepth(n2kMsg,1,dbs,offset); //on the N2K side we always have depth below transducer
send(n2kMsg,msg.sourceId,(n2kMsg.PGN)+String((offset >=0)?1:0));
}
}
}

View File

@ -267,21 +267,29 @@ private:
double DepthBelowTransducer;
double Offset;
double Range;
double WaterDepth;
if (ParseN2kWaterDepth(N2kMsg, SID, DepthBelowTransducer, Offset, Range))
{
WaterDepth = DepthBelowTransducer + Offset;
updateDouble(boatData->DBS, WaterDepth);
updateDouble(boatData->DBT,DepthBelowTransducer);
tNMEA0183Msg NMEA0183Msg;
if (NMEA0183SetDPT(NMEA0183Msg, DepthBelowTransducer, Offset,talkerId))
if (updateDouble(boatData->DBT, DepthBelowTransducer))
{
SendMessage(NMEA0183Msg);
}
if (NMEA0183SetDBx(NMEA0183Msg, DepthBelowTransducer, Offset,talkerId))
{
SendMessage(NMEA0183Msg);
tNMEA0183Msg NMEA0183Msg;
bool offsetValid=true;
if (N2kIsNA(Offset)) {
Offset=NMEA0183DoubleNA;
offsetValid=false;
}
if (NMEA0183SetDPT(NMEA0183Msg, DepthBelowTransducer, Offset, talkerId))
{
SendMessage(NMEA0183Msg);
}
if (offsetValid)
{
double WaterDepth = DepthBelowTransducer + Offset;
updateDouble(boatData->DBS, WaterDepth);
}
if (NMEA0183SetDBx(NMEA0183Msg, DepthBelowTransducer, Offset, talkerId))
{
SendMessage(NMEA0183Msg);
}
}
}
}