Skip to content

Commit

Permalink
added support for PGN 127258 - magnetic variation
Browse files Browse the repository at this point in the history
  • Loading branch information
adwuk committed Nov 10, 2016
1 parent f66c408 commit c5f3d76
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
23 changes: 23 additions & 0 deletions N2kMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ bool ParseN2kPGN127257(const tN2kMsg &N2kMsg, unsigned char &SID, double &Yaw, d
return true;
}

//*****************************************************************************
// Magnetic variation
void SetN2kPGN127258(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation) {
N2kMsg.SetPGN(127258L);
N2kMsg.Priority=3;
N2kMsg.AddByte(SID);
N2kMsg.AddByte(Source & 0x0f);
N2kMsg.Add2ByteUInt(DaysSince1970);
N2kMsg.Add2ByteDouble(Variation, 0.0001);
}

bool ParseN2kPGN127258(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation) {
if (N2kMsg.PGN!=127258L) return false;

int Index=0;
SID=N2kMsg.GetByte(Index);
Source=(tN2kMagneticVariation) (N2kMsg.GetByte(Index) & 0x0f);
DaysSince1970=N2kMsg.Get2ByteUInt(Index);
Variation=N2kMsg.Get2ByteDouble(0.0001, Index);

return true;
}

//*****************************************************************************
// Engine rapid param
void SetN2kPGN127488(tN2kMsg &N2kMsg, unsigned char EngineInstance, double EngineSpeed,
Expand Down
33 changes: 33 additions & 0 deletions N2kMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ enum tN2kAISMode {
N2kaismode_Autonomous=0,
N2kaismode_Assigned=1,
};
enum tN2kMagneticVariation {
N2kmagvar_Manual=0,
N2kmagvar_Chart=1,
N2kmagvar_Table=2,
N2kmagvar_Calc=3,
N2kmagvar_WMM2000=4,
N2kmagvar_WMM2005=5,
N2kmagvar_WMM2010=6,
N2kmagvar_WMM2015=7,
N2kmagvar_WMM2020=8,
};

//*****************************************************************************
// System date/time
Expand Down Expand Up @@ -352,6 +363,28 @@ inline bool ParseN2kAttitude(const tN2kMsg &N2kMsg, unsigned char &SID, double &
return ParseN2kPGN127257(N2kMsg,SID, Yaw, Pitch, Roll);
}

//*****************************************************************************
// Magnetic Variation
// Input:
// - SID Sequence ID. If your device is e.g. boat speed and heading at same time, you can set same SID for different messages
// to indicate that they are measured at same time.
// - Source How was the variation value generated
// - DaysSince1970 Days since January 1, 1970
// - Variation Magnetic variation/declination in radians
// Output:
// - N2kMsg NMEA2000 message ready to be send.
void SetN2kPGN127258(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation);

inline void SetN2kMagneticVariation(tN2kMsg &N2kMsg, unsigned char SID, tN2kMagneticVariation Source, uint16_t DaysSince1970, double Variation) {
SetN2kPGN127258(N2kMsg, SID, Source, DaysSince1970, Variation);
}

bool ParseN2kPGN127258(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation);

inline bool ParseN2kMagneticVariation(const tN2kMsg &N2kMsg, unsigned char &SID, tN2kMagneticVariation &Source, uint16_t &DaysSince1970, double &Variation) {
return ParseN2kPGN127258(N2kMsg, SID, Source, DaysSince1970, Variation);
}

//*****************************************************************************
// Engine parameters rapid
// Input:
Expand Down

0 comments on commit c5f3d76

Please sign in to comment.