MWV to n2k
This commit is contained in:
parent
7aaccac54b
commit
702cac2a83
|
@ -91,39 +91,42 @@ template<class T> class GwBoatItem : public GwBoatItemBase{
|
||||||
};
|
};
|
||||||
|
|
||||||
static double formatCourse(double cv)
|
static double formatCourse(double cv)
|
||||||
{
|
{
|
||||||
double rt = cv * 180.0 / M_PI;
|
double rt = cv * 180.0 / M_PI;
|
||||||
if (rt > 360)
|
if (rt > 360)
|
||||||
rt -= 360;
|
rt -= 360;
|
||||||
if (rt < 0)
|
if (rt < 0)
|
||||||
rt += 360;
|
rt += 360;
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
static double formatWind(double cv)
|
static double formatDegToRad(double deg){
|
||||||
{
|
return deg/180.0 * M_PI;
|
||||||
double rt = formatCourse(cv);
|
}
|
||||||
if (rt > 180)
|
static double formatWind(double cv)
|
||||||
rt = 180 - rt;
|
{
|
||||||
return rt;
|
double rt = formatCourse(cv);
|
||||||
}
|
if (rt > 180)
|
||||||
static double formatKnots(double cv)
|
rt = 180 - rt;
|
||||||
{
|
return rt;
|
||||||
return cv * 3600.0 / 1852.0;
|
}
|
||||||
}
|
static double formatKnots(double cv)
|
||||||
|
{
|
||||||
|
return cv * 3600.0 / 1852.0;
|
||||||
|
}
|
||||||
|
|
||||||
static uint32_t mtr2nm(uint32_t m)
|
static uint32_t mtr2nm(uint32_t m)
|
||||||
{
|
{
|
||||||
return m / 1852;
|
return m / 1852;
|
||||||
}
|
}
|
||||||
static double mtr2nm(double m)
|
static double mtr2nm(double m)
|
||||||
{
|
{
|
||||||
return m / 1852;
|
return m / 1852;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double kelvinToC(double v){
|
|
||||||
return v-273.15;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static double kelvinToC(double v)
|
||||||
|
{
|
||||||
|
return v - 273.15;
|
||||||
|
}
|
||||||
|
|
||||||
#define GWBOATDATA(type,name,time,fmt) \
|
#define GWBOATDATA(type,name,time,fmt) \
|
||||||
GwBoatItem<type> *name=new GwBoatItem<type>(F(#name),time,fmt,&values) ;
|
GwBoatItem<type> *name=new GwBoatItem<type>(F(#name),time,fmt,&values) ;
|
||||||
|
|
|
@ -225,6 +225,38 @@ private:
|
||||||
void convertAIVDX(const SNMEA0183Msg &msg){
|
void convertAIVDX(const SNMEA0183Msg &msg){
|
||||||
aisDecoder->handleMessage(msg.line);
|
aisDecoder->handleMessage(msg.line);
|
||||||
}
|
}
|
||||||
|
void convertMWV(const SNMEA0183Msg &msg){
|
||||||
|
double WindAngle,WindSpeed;
|
||||||
|
tNMEA0183WindReference Reference;
|
||||||
|
|
||||||
|
if (!NMEA0183ParseMWV_nc(msg, WindAngle, Reference,WindSpeed))
|
||||||
|
{
|
||||||
|
logger->logDebug(GwLog::DEBUG, "failed to parse MWV %s", msg.line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tN2kMsg n2kMsg;
|
||||||
|
tN2kWindReference n2kRef;
|
||||||
|
bool shouldSend=false;
|
||||||
|
WindAngle=formatDegToRad(WindAngle);
|
||||||
|
switch(Reference){
|
||||||
|
case NMEA0183Wind_Apparent:
|
||||||
|
n2kRef=N2kWind_Apparent;
|
||||||
|
shouldSend=updateDouble(boatData->AWA,WindAngle,msg.sourceId) &&
|
||||||
|
updateDouble(boatData->AWS,WindSpeed,msg.sourceId);
|
||||||
|
break;
|
||||||
|
case NMEA0183Wind_True:
|
||||||
|
n2kRef=N2kWind_True_North;
|
||||||
|
shouldSend=updateDouble(boatData->TWD,WindAngle,msg.sourceId) &&
|
||||||
|
updateDouble(boatData->TWS,WindSpeed,msg.sourceId);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_DEBUG(GwLog::DEBUG,"unknown wind reference %d in %s",(int)Reference,msg.line);
|
||||||
|
}
|
||||||
|
if (shouldSend){
|
||||||
|
SetN2kWindSpeed(n2kMsg,1,WindSpeed,WindAngle,n2kRef);
|
||||||
|
send(n2kMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
//shortcut for lambda converters
|
//shortcut for lambda converters
|
||||||
#define CVL [](const SNMEA0183Msg &msg, NMEA0183DataToN2KFunctions *p) -> void
|
#define CVL [](const SNMEA0183Msg &msg, NMEA0183DataToN2KFunctions *p) -> void
|
||||||
void registerConverters()
|
void registerConverters()
|
||||||
|
@ -234,6 +266,9 @@ private:
|
||||||
converters.registerConverter(
|
converters.registerConverter(
|
||||||
126992UL,129025UL,129026UL,127258UL,
|
126992UL,129025UL,129026UL,127258UL,
|
||||||
String(F("RMC")), &NMEA0183DataToN2KFunctions::convertRMC);
|
String(F("RMC")), &NMEA0183DataToN2KFunctions::convertRMC);
|
||||||
|
converters.registerConverter(
|
||||||
|
130306UL,
|
||||||
|
String(F("MWV")),&NMEA0183DataToN2KFunctions::convertMWV);
|
||||||
unsigned long *aispgns=new unsigned long[7]{129810UL,129809UL,129040UL,129039UL,129802UL,129794UL,129038UL};
|
unsigned long *aispgns=new unsigned long[7]{129810UL,129809UL,129040UL,129039UL,129802UL,129794UL,129038UL};
|
||||||
converters.registerConverter(7,&aispgns[0],
|
converters.registerConverter(7,&aispgns[0],
|
||||||
String(F("AIVDM")),&NMEA0183DataToN2KFunctions::convertAIVDX);
|
String(F("AIVDM")),&NMEA0183DataToN2KFunctions::convertAIVDX);
|
||||||
|
|
|
@ -288,6 +288,12 @@ private:
|
||||||
updateDouble(boatData->AWS, WindSpeed);
|
updateDouble(boatData->AWS, WindSpeed);
|
||||||
setMax(boatData->MaxAws, boatData->AWS);
|
setMax(boatData->MaxAws, boatData->AWS);
|
||||||
}
|
}
|
||||||
|
if (WindReference == N2kWind_True_North)
|
||||||
|
{
|
||||||
|
NMEA0183Reference = NMEA0183Wind_True;
|
||||||
|
updateDouble(boatData->TWD, WindAngle);
|
||||||
|
updateDouble(boatData->TWS, WindSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
if (NMEA0183SetMWV(NMEA0183Msg, formatCourse(WindAngle), NMEA0183Reference, WindSpeed))
|
if (NMEA0183SetMWV(NMEA0183Msg, formatCourse(WindAngle), NMEA0183Reference, WindSpeed))
|
||||||
SendMessage(NMEA0183Msg);
|
SendMessage(NMEA0183Msg);
|
||||||
|
|
Loading…
Reference in New Issue