NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
N2kMaretron.cpp
Go to the documentation of this file.
1/*
2N2kMaretron.cpp
3
4Copyright (c) 2019-2024 Vassilis Bourdakis,
5 Timo Lappalainen, Kave Oy, www.kave.fi,
6
7Authors Vassilis Bourdakis
8 Timo Lappalainen
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to use,
13copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
14Software, and to permit persons to whom the Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
25OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26*/
27
28#include "N2kTypes.h"
29#include "N2kMaretron.h"
30#include <string.h>
31
32#define MaretronProprietary 0x9889 // Maretron 137 + reserved + industry code=marine
33
34
35//*****************************************************************************
36// Temperature High Range [MARETRON TMP100]
37// Temperatures should be in Kelvin
38void SetN2kMaretronPGN130823(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource,
39 double ActualTemperature, double SetTemperature) {
40 N2kMsg.SetPGN(130823L);
41 N2kMsg.Priority=5;
43 N2kMsg.AddByte(SID);
44 N2kMsg.AddByte((unsigned char)TempInstance);
45 N2kMsg.AddByte((unsigned char)TempSource);
46 N2kMsg.Add2ByteUDouble(ActualTemperature,0.1);
47 N2kMsg.Add2ByteUDouble(SetTemperature,0.1);
48}
49
50bool ParseN2kMaretronPGN130823(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource,
51 double &ActualTemperature, double &SetTemperature) {
52 if (N2kMsg.PGN!=130823L) return false;
53 int Index=0;
54 if (N2kMsg.Get2ByteUInt(Index)!=MaretronProprietary ) return false;
55 SID=N2kMsg.GetByte(Index);
56 TempInstance=N2kMsg.GetByte(Index);
57 TempSource=(tN2kTempSource)(N2kMsg.GetByte(Index));
58 ActualTemperature=N2kMsg.Get2ByteUDouble(0.1,Index);
59 SetTemperature=N2kMsg.Get2ByteUDouble(0.1,Index);
60 return true;
61}
62
63//*****************************************************************************
64// Fluid Flow Rate [MARETRON FFM100]
65// Flow unit is 1 lt/hour
66void SetN2kMaretronPGN65286(tN2kMsg &N2kMsg, unsigned char SID, unsigned char FlowRateInstance, tN2kFluidType FluidType,
67 double FluidFlowRate) {
68 N2kMsg.SetPGN(65286L);
69 N2kMsg.Priority=5;
71 N2kMsg.AddByte(SID);
72 N2kMsg.AddByte((unsigned char)FlowRateInstance);
73 N2kMsg.AddByte((unsigned char)FluidType);
74 N2kMsg.Add3ByteDouble(FluidFlowRate,0.1);
75}
76
77bool ParseN2kMaretronPGN65286(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &FlowRateInstance, tN2kFluidType &FluidType,
78 double &FluidFlowRate) {
79 if (N2kMsg.PGN!=65286L) return false;
80 int Index=0;
81 if (N2kMsg.Get2ByteUInt(Index)!=MaretronProprietary ) return false;
82 SID=N2kMsg.GetByte(Index);
83 FlowRateInstance=N2kMsg.GetByte(Index);
84 FluidType=(tN2kFluidType)(N2kMsg.GetByte(Index));
85 FluidFlowRate=N2kMsg.Get3ByteDouble(0.1,Index);
86 return true;
87}
88
89//*****************************************************************************
90// Trip Volume [MARETRON FFM100]
91// Volume unit is 1 litre
92void SetN2kMaretronPGN65287(tN2kMsg &N2kMsg, unsigned char SID, unsigned char VolumeInstance, tN2kFluidType FluidType,
93 double TripVolume) {
94 N2kMsg.SetPGN(65287L);
95 N2kMsg.Priority=5;
97 N2kMsg.AddByte(SID);
98 N2kMsg.AddByte((unsigned char)VolumeInstance);
99 N2kMsg.AddByte((unsigned char)FluidType);
100 N2kMsg.Add3ByteDouble(TripVolume,1);
101}
102
103bool ParseN2kMaretronPGN65287(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &VolumeInstance, tN2kFluidType &FluidType,
104 double &TripVolume) {
105 if (N2kMsg.PGN!=65287L) return false;
106 int Index=0;
107 if (N2kMsg.Get2ByteUInt(Index)!=MaretronProprietary ) return false;
108 SID=N2kMsg.GetByte(Index);
109 VolumeInstance=N2kMsg.GetByte(Index);
110 FluidType=(tN2kFluidType)(N2kMsg.GetByte(Index));
111 TripVolume=N2kMsg.Get3ByteDouble(1,Index);
112 return true;
113}
void SetN2kMaretronPGN130823(tN2kMsg &N2kMsg, unsigned char SID, unsigned char TempInstance, tN2kTempSource TempSource, double ActualTemperature, double SetTemperature)
Setting up PGN 130823 for Maretron Message "Temperature High Range".
Definition: N2kMaretron.cpp:38
bool ParseN2kMaretronPGN130823(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &TempInstance, tN2kTempSource &TempSource, double &ActualTemperature, double &SetTemperature)
Parsing the content of Maretron Message PGN 130823 "Temperature High Range".
Definition: N2kMaretron.cpp:50
void SetN2kMaretronPGN65286(tN2kMsg &N2kMsg, unsigned char SID, unsigned char FlowRateInstance, tN2kFluidType FluidType, double FluidFlowRate)
Setting up PGN 65286 for Maretron Message "Fluid Flow Rate".
Definition: N2kMaretron.cpp:66
void SetN2kMaretronPGN65287(tN2kMsg &N2kMsg, unsigned char SID, unsigned char VolumeInstance, tN2kFluidType FluidType, double TripVolume)
Setting up PGN 65287 for Maretron Message "Trip Volume".
Definition: N2kMaretron.cpp:92
#define MaretronProprietary
Definition: N2kMaretron.cpp:32
bool ParseN2kMaretronPGN65287(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &VolumeInstance, tN2kFluidType &FluidType, double &TripVolume)
Parsing the content of Maretron Message PGN 65287 "Trip Volume".
bool ParseN2kMaretronPGN65286(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &FlowRateInstance, tN2kFluidType &FluidType, double &FluidFlowRate)
Parsing the content of Maretron Message PGN 65286 "Fluid Flow Rate".
Definition: N2kMaretron.cpp:77
Collection of functions for handling NMEA2000 bus Maretron messages.
This File contains all specific Enumerations to make NMEA2000 Messages easier for humans to read.
This class contains all the data of an NMEA2000 message.
Definition: N2kMsg.h:656
void Add2ByteUDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 2 bytes.
Definition: N2kMsg.cpp:156
void Add2ByteUInt(uint16_t v)
Add unsigned integer value to the buffer using 2 bytes The value will be added to the end (indicated ...
Definition: N2kMsg.cpp:188
double Get3ByteDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 3 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:324
void Add3ByteDouble(double v, double precision, double UndefVal=N2kDoubleNA)
Add double value to the buffer using 3 bytes.
Definition: N2kMsg.cpp:138
void AddByte(unsigned char v)
Add byte value to the buffer The byte will be added to the end (indicated by DataLen) of the byte arr...
Definition: N2kMsg.cpp:208
uint16_t Get2ByteUInt(int &Index, uint16_t def=0xffff) const
Get an unsigned integer from 2 bytes out of Data.
Definition: N2kMsg.cpp:268
double Get2ByteUDouble(double precision, int &Index, double def=N2kDoubleNA) const
Get a double from 2 bytes out of Data The fixed point integer mechanism is used.
Definition: N2kMsg.cpp:317
unsigned char Priority
Priority of the NMEA2000 message.
Definition: N2kMsg.h:665
void SetPGN(unsigned long _PGN)
Set the Parameter Group Number of the message *.
Definition: N2kMsg.cpp:68
unsigned char GetByte(int &Index) const
Get the value from a byte out of Data.
Definition: N2kMsg.cpp:254
unsigned long PGN
Parameter Group Number (PGN) of the NMEA2000 message.
Definition: N2kMsg.h:667
tN2kTempSource
Enumeration of sources for a temperature value according to PGN130311, PGN130312 and PGN130316.
Definition: N2kTypes.h:171
tN2kFluidType
Enumeration of fluid types according to PGN127505.
Definition: N2kTypes.h:234