Git Product home page Git Product logo

nmea2000's Introduction

NMEA2000 library for C++

NMEA2000 library is object oriented C++ library for developing NMEA2000 bus devices. Library fulfills automatically NMEA 2000 mandatory requirements leaving only interesting data handling for developer. Library has been used in several commercial certified NMEA2000 devices.

Library provides you easy way to make different kind of NMEA2000 bus devices like sensor transducers (battery, temperature, wind, engine, etc.), NMEA2000 information displays,NMEA2000→PC interface (like Actisense NGT1), NMEA0183→NMEA2000 or NMEA2000→NMEA0183 converter.

Library has been originally (2015) developed for Arduino based boards. As far as I know it has been used and tested with Teensy, ESP, some Arduino, MBED and Rasberry Boards, but library can be used also in other systems by writing compatible CAN "driver" and necessary classes for other hw specific functions.

If you are familiar with library, here is quick link to the changes: https://ttlappalainen.github.io/NMEA2000/changes.html

Read more from the full documentation on Github Pages: https://ttlappalainen.github.io/NMEA2000/index.html

License

MIT license

Copyright (c) 2015-2024 Timo Lappalainen, Kave Oy, www.kave.fi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nmea2000's People

Contributors

adwuk avatar andrei-errapart avatar atinstrumentssam avatar denravonska avatar ericvandervelde avatar garaminowicz avatar ivankravets avatar jboynes avatar johnmacrae avatar jpilet avatar kimbp avatar lsoltero avatar mairas avatar matthias-mw avatar mrbubble62 avatar nicklasb avatar pabbott-lumitec avatar peterfromsweden avatar phatpaul avatar preeve9534 avatar remcohalman avatar ronzeiller avatar sanderv4n avatar sarfata avatar thomasonw avatar tmcadam avatar trixpan avatar ttlappalainen avatar xslim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nmea2000's Issues

PGN 126992 SystemTime

Hi Timo
The Nmea Doc says:
26992
The purpose of this PGN isto provide a regular transmission of UTC time and date; optionally synchronized to other parameter
groups from the same source.
Field # Field Description
1 Sequence ID
2 Source
3 NMEA Reserved
4 Date
5 Time

The same ist true for actisense NMEA reader:
image

but in the lib it is:
// System date/time
// 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.
// - SystemDate Days since 1970-01-01
// - SystemTime seconds since midnight
// - TimeSource see tN2kTimeSource

Is this a bug?

best regards Uwe

NMEA2000 interfering with reading Serial input.

I have wind sensor (Nano) sending data via RS485 to a Mega running NMEA2000 library and transferring the sensor values over NMEA200 bus onto my Garmin echoMap. The system is working fine when everything is connected however when the Mega is physically disconnected from the NMEA200 bus or the Garmin is switched off, the RS485 connection is failing. It seems that NMEA2000 is somehow interfering with reading the serial on the Mega, when it can't send messages (disconnected). I have tried connecting the RS485 to the different RX/TX ports on the Mega and still find the same behaviour. I have all serial output disabled in NMEA2000. Is SPI using the same buffers as the RS485 using and MCP2515 is sending something back to the Mega if it can't send? I thought they would be separate. Is there a delay in NMEA2000 or mcp_can if it can't send a message? But this shouldn't really matter as my buffer is never getting above (12 bytes).

It's not blocking my project, I don't really need RS485 when the device isn't connected to the NMEA2000 bus, but I would like to understand where the problem is coming from. Thanks

PGN 65240 ISO Commanded address

Hi,

I would like to add support for PGN 65240 to library. With this PGN some device can be commanded to change its source address to specified on command. Does anybody have system for testing it? I can write tester to my NMEA Simulator, but it should be proved with some "certified" system.

Merging data from two physical N2K devices on PGN127489 [Engine Parameters] ?

hello Timo et al,

more of a Question but I'm stuck at the moment and want to prepare code and test it over the weekend on the boat.
I have a No Land Engineering RS11 engine monitor setup (before finding you and your work, otherwise I wouldn't buy it!) which gives to the bus

  • Oil Pressure
  • Coolant Temp
  • Engine Boost
  • RMP

for two engines.

Works fine and Garmin GMI10s and GPSMAP4008 see and present the data.

Now, working on a teensy which will take:

  • exhaust gas temperature
  • gearbox oil pressure
  • gearbox oil temperature

and pass them onto the bus.
So two physical devices, two different addresses, both sending PGN127489 data to the bus.
Q::
A. in my teensy, should I first read the bus for this message (effectively picking the RS11 info), merge my 3 data (x2 for the two engines...) and resent it to the bus?
or
B. just formulate the sentence and sent my 3 data (x2) and hopefully they will merge with the others?

Note, I wont be sending the SAME info, just adding new info to the SAME PGN. Haven't done that before, so bit confused.

Afraid that on option two I'll have blinking data for all 6 parameters, or a massive messup!

thanks!

Vassilis

Not responding to PNG 59904 Request for PNG 126996

The library should automatically respond to a request for product information (PNG 126996) but it does not appear to do so

I am using two Teensy 3.1 and a Lowrance HDS7 Gen1. I view through the actisense software to monitor the bus.

The library properly responds to 60928 with another 60928.
My MFD then requests product information with PNG 59904 but the library does not respond

What would the proper way to respond in my code be?

Parse N2kPGN128259 Boat Speed -> error?

Generating PGNs with Kave NMEA Simulator writing to NMEA200 Bus, reading from Bus with NMEA2000 Library PGN 128259 Boat Speed:

Parsing the PGN gives for WaterRefereced and GroundReferenced always the same value.
If there is current set in Simulator then WaterRefereced and GroundReferenced are both the values for GroundReferenced.
In other words WaterRefereced shows actual GroundReferenced value.

In the library in N2kMessages.cpp itself there is:
In SetN2kPGN128259: twice N2kMsg.Add2ByteUDouble
In ParseN2kPGN128259: Line 546 --> Get2ByteDouble(0.01,Index) (without U)

(Is another issue, as it does not make any difference for the values)

DynamicTransmission flags not implemented as bools

DynamicTransmission has Transmission Oil Pressure as well as Oil Temperature, but does not have a way similar to DynamicEngine to trigger specific flags. The flags are as follows:
Transmission Sail Drive - Bit 5
Transmission Low Oil Level - Bit 4
Transmission Low Oil Pressure - Bit 3
Transmission Over Temp - Bit 2
Transmission Check - Bit 1

Getting TemperatureMonitor running on ArduinoDue

Hej
Your library is really great and comprehensive... However, i still dont get it running :-(
After unsuccessfully trying some time ago with a custom Atmel AT90CAN board (previous topic) i now obtained an original ArduinoDue board, hoping that it would run from scratch with this. But somehow i still dont have success.

I have an ArduinoDue connected to a Garmin GPSMap 720, and would like to display a tank level later. For the time being, i have installed the TempMonitor example, using NMEA2000, NMEA2000_due and due_can libraries (latest versions) from this git repository. I got everything compiled without problems in the arduino ide, and uploaded the sketch.

But somehow the device does not appear in the "devicelist" on the Garmin gpsmap, and i think the address claim procedure is failing for some unknown reason.
I am pretty sure the NMEA2000 bus is cabled correctly. I checked with a scope, and i see quite some traffic from the GPSMAP 720, on both CANH and CANL line. I also see the traffic on the CAN_Receive pin on the arduino board, and i see a little traffic on the CAN_Transmit pin, which looks like the CAN Acknowledge bits, send for every received package. Its somehow correlated with the messages sent by the Garmin GPSMAP. But it looks like there is no outgoing messages from the arduinoDue.

The messages on the "serial monitor" say:
Start Initialize buffers
CAN device ready
Start address claim for device 0

and thats it.

if i put:
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode,23);
NMEA2000.EnableForward(true);
Then i see a constant stream of messages with weird PGN (mostly 2048), but these even come in if i switch of the GARMIN GPSMAP, so i have no clue where they could come from.

[...]
5953 : Pri:0 PGN:2048 Source:211 Dest:127 Len:8 Data:C4,3F,8,0,0,50,0,21
15959 : Pri:0 PGN:2048 Source:197 Dest:63 Len:8 Data:0,0,0,B0,F,20,8,0
15965 : Pri:0 PGN:2048 Source:211 Dest:127 Len:8 Data:C4,3F,8,0,0,E0,0,21
15972 : Pri:0 PGN:2048 Source:38 Dest:46 Len:8 Data:0,0,0,B0,F,20,8,0
15979 : Pri:0 PGN:2048 Source:211 Dest:127 Len:8 Data:C4,3F,8,0,0,E0,0,21
[...]

To me it looks like there is still a problem with my installed version of the library, or maybe the interplay of the different libraries, but i am running out of ideas what and how to further test.
Was this recently tested on an ArduinoDue ?

And a last, probably unconnected observation:
If i try to change anything inside NMEA2000_CompilerDefns.h, uncommenting any of the #DEFINES there, then i can no longer compile.

Can anyone help, or have some advice ?
Can i somehow activate more debug messages on the serial monitor ?
Any other hints ???

Probably i am doing some stupid mistake. I am pretty sure its not on the hardware side...

Thanks for any help,
Christian

Logging N2k-Bus data

Hi Timo,
thinking of logging bus datas in Actisense format, because it is the smallest (data format).

This function should be integrated into my "normal" program as an option.
There is a handler and in another class I get hold on the N2kMsg (N2kMsg.PGN, N2kMsg.MsgTime etc. ) for some manipulations.

For logging I actually do not have a stream, but would need a String with the Actisense formatted datas to hand over to a "write to SD-Card" function.
As there is no timestamp in Actisense format (right?) I would add millis() to the string.

Quite desperate because I did not find a working solution, but may be I just do not see "the forest because of all the trees" as we say here :-)

Could you please help?

As logging without reading the datas later on would not make sense, could you give me a hint how this could be done too? (Here would be separate code for reading the sd-card over serial and the normal read stream handler should work, right?)

Thank You!

purpose of SetProductInformation and SetDeviceInformation

Hi Timo

I think I have some problems in understanding the functions SetProductInformation and SetDeviceInformation. I using a teensy with CAN-Bus driver and have connected it to my SeaTalk NG. Using for example the BatteryMonitor with N2km_ListenAndNode is can see all the N2K-Messages on the bus using NMEA Reader and also see my own messages (Voltages etc.) . But I never saw any messages with the infos of SetProductInformation and SetDeviceInformation. I would expect, that the PGN 126996 Product information would be transmitted for this purpose. On my other N2K devices the 126996 is either send periodically or - true for the raymarine device - on request from a MFD.

please clerify
Best Regards Uwe

pressure issue with PGN 130310 and 130311

In N2kMessages.h at the PGNs 130310 and 130311 the comment says "AtmosphericPressure Atmospheric pressure in Pascals. Use function mBarToPascal, if you like to use mBar"
But when I feed 1234.5 mBar with mBarToPascal the result on Raymarine i70 is 14964 and in Actisense NMEA Reader 5791400 pascal.
When I do not use the mBarToPascal-conversion, everythink looks fine. i70 show 1235 and in NMEA Reader say 123500 pascal.
Is the comment wrong?
please clearify.

Thanks Uwe

read ProductInformation and DeviceInformation from N2k Bus

Hello Timo
How can I READ ProductInformation and DeviceInformation (PGN:60928, PGN:126996 und PGN:126998) from N2k Bus?
In your Examples you describe very clear and detailed how to SEND this Information to the N2k Bus but I was not able to understand how to READ this very interresting information about the other devices on the N2k bus like Garmin...
All I could find was the function GetDeviceInformation (not even sure if this is the right one) but even this does not compile when called like: NMEA2000.GetDeviceInformation(); and creates fault: class tNMEA2000 has no member named "GetDeviceInformation" .
Please could you help me on this issue?
And I guess this would be interresting for others as well and should be added to one of the examples.
Best Regards, Peter

GNSS info decimal problem

GNSS info long and latitude only have 2 decimal so the outpust is rounded.
If I look up the coordinates it is a block away from where i am beacause the output is rouded with only 2 decimals This is the output i get:
latitude: 52.34
longitude: 5.53
is there any whay to get the full sentence?

Understanding N2K device selection

Hi Timo

hopefully you can help me in unstanding the behaivior of N2K devices. How selects a receiving device the "correct" source, if more than one device on the bus are sendind the same type of information. Is there a selection mechanism or so?

Best Regards Uwe

Leeway PGN 128000

I could not find the leeway PGN here so did this. I would do a patch, but I need to update version of your libraries first, and probably my display software.


// Leeway
// https://www.nmea.org/Assets/20170204%20nmea%202000%20leeway%20pgn%20final.pdf
// 4x per second.
void fillLeeway(tN2kMsg &N2kMsg) {
    N2kMsg.SetPGN(128000L);
    N2kMsg.Priority=4;
    N2kMsg.AddByte(sid);
    // int16  leeway/1E-4 in radians fro +pi to -pi +ve means leeway to starboard.
    N2kMsg.Add2ByteInt((int16_t)((double)leeway/(double)1.0E-4F));
    // 40 bits = 5 bytes, wonder what these will be used for ?
    N2kMsg.AddByte(0xff); // Reserved
    N2kMsg.AddByte(0xff); // Reserved
    N2kMsg.AddByte(0xff); // Reserved
    N2kMsg.AddByte(0xff); // Reserved
    N2kMsg.AddByte(0xff); // Reserved
}

Support for Teensy 3.5/3.6

Timo, I'm just starting to test your excellent libraries on a Teensy 3.5. I haven't set up with a real NMEA bus yet so haven't tested that part, but to get it to build I had to modify NMEA200_CAN.h as follows to include the new processors:

#elif defined(MK20DX256)||defined(ATMEGA32U4) || defined(MK64FX512) || defined (MK66FX1M0)
#define USE_N2K_CAN USE_N2K_TEENSY_CAN

I'm not familiar enough with GIT to use the proper change processes but thought I'd feed this back now. I'll update you when I've done some more testing.
Steve.

PNG127245 Rudder no Parse function (only set)

Great Libary. Many Thanks to the Autor(s).
But one thing is missing. A Parse Function for the "Current Rudder Position".

I tryed to make the necessary changens in N2kMessages.h and N2kMessages.cpp Libary Files but I failed because looks like this Sentence is somehow special with this "Instance" instead of "SID" on another Position ...

Is there any Plan to create a Parse Function or is there allready another solution?
Would be great because for Performance sailing the Current Rudder Angle is a important parameter you don't wana miss

Many Thanks for any Help
Peter

Remove Arduino dependencies

I know this library was written with Arduino in mind, but I think that with some smaller modifications it could be made platform agnostic. Have a look at my suggestions and let me know what you think. I can fix these in my fork and submit a pull request.

  • Remove Arduino.h includes.
  • Replace bit operations with shifts. B00000100 becomes (1 << 2).
  • Move debug print operations to a separate N2kDebug.h/cpp.
  • Replace bracket includes with quotation includes for local files (merely cosmetic, but I got a compiler warning. #include <N2kMessages.h> becomes #include "N2kMessages.h".
  • Replace lowByte/highByte with shift operations. highByte(v) becomes (v >> 8) & 0xFF.
  • Leave millis() as it is and declare it external where it's used. This and CAN would be the application requirements. On Arduino it should work as-is while other platforms can wrap their own clock inside their millis function.
  • Functions which just want a Stream to read from or write to could accept functors instead.

The examples would remain Arduino and no sketches would be modified. It's just the source that would need some massaging for non-Arduino users.

STM32F103C8 Bluepill new library

Hi, thanks a lot for your project.

I have done a CAN library that uses the ST official arduino port for the stm32.

https://github.com/stm32duino
The library is at
https://github.com/jiauka/NMEA2000_stm32f1

To use it, the NMEA2000_CAN.h needs some tweak.

#elif defined(STM32F103xB)||defined(STM32F103xB)
#define USE_N2K_CAN USE_N2K_STM32F1xx_CAN

#elif USE_N2K_CAN == USE_N2K_STM32F1xx_CAN
#include <NMEA2000_stm32f1.h>
tNMEA2000 &NMEA2000=*(new NMEA2000_stm32f1());

Thanks again!!
j.

Teensy 3.2 not work with "universal" FlexCAN Libary

Follow instructions to use Teensy 3.2 for Example: NMEA2000/Examples/ TeensyActisenseListenerSender you have to download and add these Libarys (in lets say C:\Program Files\libaries):

  • Teensyduino
  • FlexCAN_Libary-master
  • NMEA2000_teensy-master
    But if doing so the example will not work because Teensyduino has allready automatically installed a "universal" version of FlexCAN Libary (FlexCAN.cpp Header says it is for Teensy 3.1-3.6), well hidden on C:\Program Files\Arduino\hardware\teensy\avr\libaries which is allways automatically taken by the Compiler. Result is that everything works but the CAN will neither send or recive any NMEA2000 data.
    -> Delete the Teensyduino FlexCAN Libary and so force the Compiler to use FlexCAN_Libary-master fixes the problem and everything works well now.

Beside that:
I do not need to add the lines as described in the instructions:
#include <NMEA2000_teensy.h>
tNMEA2000_teensy NMEA2000;
Is this correct because the instruction say I should use it?

Thanks and best regards

NMEA2000 on a linux box

Hi,

I want to read, as a start position, course, speed on my boat running NMEA2000. I have a on the boat pc running Linux. Would this library be able to help reading from the NMEA2000 net ?

Do there exist a list of all sentences interpreted ? ( I might later be interested in info from the engine )

Best regards
Håvard

Negative headings from PGN 127250

In N2KMessages.cpp, ParseN2kPGN127250 returns negative values for headings between 180 and 360. I think Heading=N2kMsg.Get2ByteDouble(0.0001,Index); needs to change to Get2ByteUDouble or am I misunderstanding something?

Overlap with Canboat

The following comment is based just on a quick look, I haven't used this library yet, so please disregard if I am mistaken here.

It seems that you are actually duplicating the information that is available in Canboat (C, XML, JSON).

This means that

  • adding PGNs that are already in Canboat is manual work
  • any updates and additions made here will not propagate to canboat and vice versa (see example)

Adding PGNs to this lib looks like something that could be done by code generation based on one of the linked files above.

Have you considered this approach?

Lowrance question

Please note this is not an issue with the code. Really a question. If there is another location questions such as this should be posted, please let me know.

I have a Lowrance HDS 5 (gen1). I am able to communicate with the device fine. I was curious if anyone has found a way to display messages on these devices? I am trying to find a way to display text generated from my application on the device for testing and diagnostic purposes.

In looking through the PGN's the device supports it seems like I might be able to use an AIS message or DSC to accomplish this? Any suggestions or tips would be appreciated.

I have tried sending PGN129802 (AIS Safety Broadcast) using the following code (my network has no AIS system or anything that would transmit or repeat this message). I have a bus monitor and can confirm the message is sent, but the Lowrance doesn't show a message in it's "Vessels->Messages" tab.

`void SendN2kAISBSafetyBroadcast()
{
static unsigned long Updated=millis();

if (Updated + 5000 < millis())
{
	tN2kMsg N2kMsg;
	Updated += 5000;
	N2kMsg.SetPGN(129802L);
	N2kMsg.Priority = 2;
	//Msg1
	N2kMsg.AddByte(14);	 	//Bits 0-5 Identifier for Message 14; always 14
					//Bits 6-7 Repeat Indicator
	N2kMsg.Add4ByteUInt(201123456);	//Bits 0-29 Source Address (IMSI)
					//Bits 30-31 Reserved (0)
	N2kMsg.AddByte(0);		//Bits 0-4 AIS Transciever Info
					//Bits 5-7 Reserved (0)
	N2kMsg.AddStr("test message", 36);
	
	NMEA2000.SendMsg(N2kMsg);
}

}`

Reference Values

Hello Timo
My question is about the Reference Value of the NMEA2000 Sentences. I think that you use the NMEA2000 Manual from the NMEA Organisation, right?
Example Wind with 4 Reference Value from your code:
https://github.com/ttlappalainen/NMEA2000/blob/master/src/N2kMessages.h (line 150-155)
150 enum tN2kWindReference {
151 N2kWind_True_North=0,
152 N2kWind_Magnetic=1
153 N2kWind_Apprent=2,
154 N2kWind_True_boat=3
155 };

But it looks like some manufators may use (different?) or at least more Reference Values as you actually do.
Example Product with 5 Reference Values: https://www.rocktheboatmarinestereo.com/specs/MSNRX200I.pdf

So my question is if I can use this 5th value (as shown in your (very good) Reader examples) just by extending the code by another "if Reference=5" or if you limit the number of the "Reference Values" in your code?

Thanks and best Regards
Peter

Changing license

Hi,

This is for all who has made changes to NMEA2000 library. I would like to change license from LGPL to MIT, which is more permissive than LGPL. This allows even companies to use library freely in their projects. I won't get millionaire anyway with this, so why keep stupid limitation. And anyway it would be fun to find after 10 years Garmin device running with this. And anyway any extra devloper may help to make library more general or robust.

So to make this 100% right I ask permission for change from all contributors.

Timo

"not valid" or empty values in N2k

Hello Timo,
how should not valid or not existed values be written in N2k sentences?

For example, if we want to write the PGN 127257 Attitude Yaw, Pitch, Roll and we do not have Yaw available what should be written?

Is there anything like in AIS where e.g. heading 361 degrees is synonym for "not valid" ?
In NMEA0183 it is just blank
In N2k?
When reading you return N2kDoubleNA if a PGN-field doesn't contain numeric information, but could it also be written? Or does it depend on the PGN?

NMEA2000_CompilerDefns.h -> uncomment fatal error at compil

Hi Timo,

After happy New Year greetings ;-) and always many thanks for the N2K library, a little remark :

when we uncomment

#define N2K_NO_ISO_MULTI_PACKET_SUPPORT 1 // Uncomment this, if you do not need ISO Multi-packet support

in

NMEA2000_CompilerDefns.h

we got, at compil, a fatal error :

In file included from C:\Users\xxxx\Documents\Arduino\libraries\NMEA2000-master\src/NMEA2000.h:50:0,

             from C:\Users\xxxx\Documents\Arduino\libraries\NMEA2000-master\src/NMEA2000_CAN.h:46,

C:\Users\xxxx\Documents\Arduino\libraries\NMEA2000-master\src/N2kCANMsg.h: In constructor 'tN2kCANMsg::tN2kCANMsg()':

C:\Users\xxxx\Documents\Arduino\libraries\NMEA2000-master\src/N2kCANMsg.h:32:75: error: class 'tN2kCANMsg' does not have any field named 'TPRequireCTS'

: Ready(false),FreeMsg(true),SystemMessage(false), KnownMessage(false), TPRequireCTS(false), TPMaxPackets(0) {

Thks again

Regards

Philippe

PGN 128275 DistanceLog

Hi Timo

Is this definition correct or is it a copy&paste error??

//*****************************************************************************
// Distance log
// Input:
// - DaysSince1970 Timestamp
// - SecondsSinceMidnight Timestamp
// - Log Total meters travelled
// - Trip Log Meters travelled since last reset
// Output:
// - N2kMsg NMEA2000 message ready to be send.
void SetN2kPGN128275(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, uint32_t Log, uint32_t TripLog);

inline void SetN2kDistanceLog(tN2kMsg &N2kMsg, uint16_t DaysSince1970, double SecondsSinceMidnight, uint32_t Log, uint32_t TripLog) {
SetN2kPGN128275(N2kMsg,DaysSince1970,SecondsSinceMidnight,Log,TripLog);

Compilation warnings : might be important.

hi Timo,

First of all thank you a lot for the great job. I'am studdying it.

I embedded with succes the librairy in my project. For test purpose.

I detect somme warnings in compilation process.

Like this one :

Arduino\libraries\NMEA2000-master\ActisenseReader.cpp:71:18: warning: comparison is always false due to limited range of data type [-Wtype-limits]

if (MsgBuf[12]>tN2kMsg::MaxDataLen) {

Might be important. You can check this, if you set in IDE pref/compilation warning : "show all"

Regards and thumb up again :-).

Philippe

Parsing a String to a N2kMsg

Hello,
thank you all for this great library.
I would like to parse a message (e.g. 15FD0780264117753421B803) to an N2kMsg Object. However I am not using an Arduino, so I started to mess around with the code to build a smaller Arduino independent lib for my project.
Sadly I didn't came very far so I am asking for help. I tried to reuse this code: ActisenseReader.cpp#L60 Is this the right place for me to start?
What exactly should the MsgBuf variable contain?
In tActisenseReader::GetMessageFromStream(tN2kMsg &N2kMsg) a NewByte is added to the MsgBuf. However MsgBuf is defined like this:
unsigned char MsgBuf[MAX_STREAM_MSG_BUF_LEN]; So if I want to manually add a string in this format is MsgBuf expected to look like this? unsigned char MsgBuf[] = {0x15, 0xFD, 0x07, 0x80, 0x26, 0x41, 0x17, 0x75, 0x34, 0x21, 0xB8, 0x03, 0};
I would really appreciate some kind of minimal code example on how to create a N2kMsg from a string like given above (created by Open Skipper)

Thank you really much.

(this is not really an issue, maybe a feature idea)

Review behavior of PGN filtering

SetForwardOnlyKnownMessages() has the documented goal of deciding if a received CAN messages is to be forward to the attached serial stream for external processing. If set=TRUE the function CheckKnownMessage() will compare incoming PGNs against the know message lists and forward those to the stream (if enabled). However, when set FALSE (Default action), ALL incoming CAN messages will be forward to the stream.

This same filtering behavior is also applied to the optional program callback SetMsgHandler(). The question is: Is this the desired behavior? That SetForwardOnlyKnownMessages() affects both streams and user SetMsgHandler() call backs?

Or, should SetForwardOnlyKnownMessages() be modified to ONLY affect streams (matching the user documentation), and a separate call be added SetHandleOnlyKnownMessages() be created?

A related question: https://github.com/ttlappalainen/NMEA2000/pull/12
Added the ability to replace the existing messages lists which are accepted by the NMEA2000 lib. By replacing the default list one is able to extend the message PGNs supported (example, other standard J1939 messages, or another J1939 overlay such as RV-C). It also allows one to 'pre-filter out' messages to the program callback which are not being used. example: A battery monitor does not need messages for GPS or AIS..

Is there a desire to add an additional API call to augment vs. replace the default messages lists?
AugmentSingleFrameMessages()
AugmentFastPacketMessages()

ttlappalainen: Did I capture these questions correctly?

-al-

Compile error on NMEA2000_teensy

Hi Timo, sorry this is in the wrong place but there doesn't seem to be an option to open an issue on NMEA2000_teensy. I'm getting a compile error on NMEA2000_teensy.cpp line 74 when compiling for a teensy 3.5.

'CAN_message_t' has no member named 'rtr'

I'm guessing line 74 is supposed to be out.timeout=0, but I'm not really sure what this code is doing so perhaps you could check.

Thanks, Steve.

ParseN2kWaterDepth Parsing -> depth not available

Parsing PGN 128267 Water depth with function from NMEA Library as written in display2.ino

PGN is coming from Kave simulator standard settings.
But PGN128267 Water depth is messaging: "Water depth is not available"

Should there not be a "!" in line 407?
if ( ! N2kIsNA(DepthBelowTransducer) ) {
......
}
otherwise it will always jump to "not available"

NMEA2000 update

hi,
I have downloaded the newest NMEA2000 Library version at 01 Sept. After the update the compiler (Arduino IDE 1.8.4) spewed out a couple error messages like this:

/home/james/Arduino/libraries/NMEA2000-master/src/NMEA2000.cpp:241:6: error: prototype for 'void tNMEA2000::ClearCharBuf(int, char*)' does not match any in class 'tNMEA2000'
void tNMEA2000::ClearCharBuf(int MaxLen, char buf) {
^
In file included from /home/james/Arduino/libraries/NMEA2000-master/src/NMEA2000.cpp:24:0:
/home/james/Arduino/libraries/NMEA2000-master/src/NMEA2000.h:78:15: error: candidate is: static void tNMEA2000::ClearCharBuf(size_t, char
)
static void ClearCharBuf(size_t MaxLen, char buf);
^
/home/james/Arduino/libraries/NMEA2000-master/src/NMEA2000.cpp:248:6: error: prototype for 'void tNMEA2000::SetCharBuf(const char
, int, char*)' does not match any in class 'tNMEA2000'
void tNMEA2000::SetCharBuf(const char *str, int MaxLen, char *buf) {

The same error on both station, MAC and Linux. It seems to be a problem with "size_t" definition, maybe.. i don't know...

rg
jan

NMEA2000_CAN.h and STM32F1

I'm trying to port my NMEA2000 application to an STM32F1 in order to get a little more resources.

I get a compile error due to include of MapleIntCompatibility.h in NMEA2000_CAN.h (added in commit 918c0d6)

Is this file supposed to come from another library or is it a file simply never committed to this library?

plain gcc makefile for examples

Hi
This is a great NMEA2000 library, and i would like to use it for a project based on a AT90CAN avr-board.
This board is unfortunately not supported in the arduino IDE, and anyway i would prefer to use plain avr-gcc compiler with makefile for the project.

However - my understanding of makefiles is not sufficient to modify one to include all the necessary nmea2000- and can-lib files to compile my own main.cpp...

As i understand, the NMEA2000 lib is already more or less independant of arduino - only the examples do need arduino IDE to compile.

For me, but maybe also for others, it would be extremely helpful, if one could include one simple example (like eg the battery monitor example) running with plain gcc. Having such an example, including a makefile, would then allow to easily adapt to own projects using this great lib.

Maybe anyone already has such an example, and is willing to post it or include it in the git ???

SetDeviceInformation for a multi device.

Hi Timo,
Do I need to set multiple DeviceInformation blocks if I want to have a device that emits data for multiple things. eg Battery, Pressure, Temp, Acceleration, Magnetometer. I am using a Due, with a I2C 10Dof chip providing that information and also want to monitor battery voltages and currents using Hall Effect current sensors. I see the

#define Max_N2kDevices 1

but have seen others sending messages for multiple classes of device. May target network is a Raymarine ng network.

Thanks. (brilliant code btw, worked first time with SignalK)
Best Regards
Ian

MessageSender/DataDisplay2 does not work as intended

I just started playing with the NMEA 2000 libraries. Great work especially from Timo ... thanks!
At first I connected two Arduino Megas (with MCP2515) as desicribed. I.e. One is running MessageSender and the other is running DataDisplay2. Did not get any packet on the receiver side.
After that, I connected an NMEA-Multiplexer (ShipModule) => all is fine, I could see the packets. With that, the transmitter (MessageSender) seems to work.
With some debugging in DataDisplay2 I discovered, that with setting "DEBUG_RXANY (1)" in MCP_CAN.cpp all is fine.
In the default way MCP is programmed to use filtering but no filters are set. And consequently, no message appears in the buffers.
There is a good chance, that I have not got all details (I am new with that technology), but simply putting together MessageSender//DataDisplay2 does not work instantly.
Any idea?

PGN128259 Speed

Hi Timo,
reading values from my NGT-1 with Actisense NMEA Reader.
Data flow:
NMEA Simulator -> USB reader with your library -> test-N2k-bus -> NGT-1 -> Actisense NMEA Reader

In PGN128259 Speed (I do not know why Actisense is writing Speed, Water referred) I have two values:
Field 2: water referenced
Field 3: ground referenced

In your simulator one can set "current"
If I turn off GPS in simulator and set some current -> Field 2 and 3 have different values.
In simulator there seems to come one PGN including field 2 and 3 both filled with values.
Is this just for simulation or is this a "normal" behavior on a boat?

Is field 3: ground referenced always filled with a value?
I am just wondering, why and from where there is coming a ground referenced speed when tN2kSpeedWaterReferenceType is not "Ultra_Sound" (which I think is ground referenced?)

Attribute imported code

Hi.

Reading through your NMEA2000 routines for some inspiration, having just read the same code in CANBoat, I find the two following functions very similar:

The number of open source NMEA2000 implementations and developers is very small. If it is based on the other work and not attributed, I think that looks very bad and diminishes your other work. I'm just a potential user of your library, and for me this was a red flag.

Please consider adding a comment with attribution where (/if) your code use code from other projects.

Getting TemperatureMonitor up and running on Arduino Uno

Hello Timo,

I tried to get the library up and running on my Arduino Uno, in debug mode. (I don't have a CAN board connected (yet)).

It behaved strange and hung after just 13 message frames. I made two changes that fixed the problem in NMEA2000.cpp:

Added a check for dbMode in the Open method (line 232) when writing the state of the CAN bus and ForwardType is Text:

if ( DeviceReady || dbMode!=dm_None)....
Otherwise you will get a lot of CAN bus failed to open

I also added a quick exit in ParseMessages (line 693):

if (dbMode != dm_None) return; // No much to do here when in Debug mode
It would otherwise try to do an address claim 13 times and the get the Uno to get stuck.

With these changes, you get a nice address claim PNG and then the temp PNG every 2,5s.

Something to consider?
(I first tried to do a pull-request from my branch)

PGN130306 Wind Data Length=6 or 8

Hi Timo,

first of all let me thank you and all the other contributors for your great work!

I had problems to show AWS and AWA in Expedition Software.
Data Input is coming from a teensy 3.6 with modified wind monitor sketch --> CAN Bus --> NGT-1 --> Expedition

I found out on comparing with candump of merrimac-actisense-serial-2011.raw that PGN130306 is always length = 8
(Sorry I have no boat with real N2k bus)

Then I recognised, that you commented out in N2KMessages.cpp at line 1165 and 1166
// N2kMsg.AddByte(0xff); // Reserved
// N2kMsg.AddByte(0xff); // Reserved

Is there any reason why it is commented out?
Because after enabling N2kMsg.AddByte(0xff); Expedition shows AWS and AWA perfectly!
And NMEA Reader is ok too.
image

Best Regards
Ronnie

Add support for PGN 127257

It would be great to have support for PGN 127257 so we can transmit and receive attitude messages (heel/pitch/roll).

It is documented in Canboat:

{ "Attitude", 127257, true, 7, 0,
  { { "SID", BYTES(1), 1, false, 0, "" }
  , { "Yaw", BYTES(2), RES_RADIANS, true, "rad", "" }
  , { "Pitch", BYTES(2), RES_RADIANS, true, "rad", "" }
  , { "Roll", BYTES(2), RES_RADIANS, true, "rad", "" }
  , { 0 }
  }
}

It would be good to know what is the reference framework too. I am guessing Yaw is relative to true north. Not sure about pitch and roll.

NMEA2000 TimeStamp in PGNs

Hi Timo,

for a project I want to write, among other things, datas from IMU-Sensor (heel and pitch) to N2k CAN-Bus (using Teensy 3.6)
I was looking at the library to find out how I could set timestamps, but it seems that the library writes millis() at init of N2kMsg.
I found no possibility to write actual time to the PGN.

On the other hand I read the N2k Bus to get actual time e.g. from PGN 126992 SYSTEM DATE/TIME
I am sorry, but I have no boat for checking real CAN bus datas.
Thus I am working with your (great!!) Kave NMEA Simulator writing to a Teensy N2k-Writer to a CAN-Bus simulation, reading the bus with another Teensy, running your library.
But when I read the PGNs from the simulator I get just millis() as N2kMsg.msgTime

My questions:

  1. is there actual real date/time in a N2k PGN-sentence on a boat CAN-bus?
    2.if yes, would it be possible (and does it make sense) to write real time into the PGN with your library, or do I have to manipulate millis()?

Thank you!
Ronnie

Teensy3.6 sending but not receaving

Dear all,
I start to use your library with Teensy 3.6 with the Dual Can transceiver found on Tindie (https://www.tindie.com/products/Fusion/dual-can-bus-adapter-for-teensy-35-36/).
The Flexcan CanTest (and the ObjectOriented test) works. Then I tried the WindMonitor coupled with a Raymarine screen and it works.
This work with:
tNMEA2000_teensy(uint16_t _DefTimeOut=4, uint8_t CANBusIndex=1); to use as default the can1
and
pinMode(35, OUTPUT);
digitalWrite(35, LOW);
as first thing in the setup() to enable the can tranceiver resistors.

The problems start when I try to see the screen or the Airmar DST800(NMEA2000) sensor or another teensy with a WindMonitor with the DataDisplay2.ino or the DeviceAnalyzer.

With the Flexcan ObjOrientedextID I check that the bus work and there is traffic but for the DataDisplay2 or DeviceAnalyzer the Bus is always OFF (Not available or empty). Also with Actisense software (that it's work with the WindMonitor) as described in the nmea2000 library manual I can't see anything.

Seems that there are problems in receiving Nmea 2000 messages on teensy but is ok in transmission.

Have you got any hints?
Thanks a lot
Paolo

Failed to open

Whenever I use these libraries CAN_BUS_Shield NMEA2000 NMEA2000_mcp

and any of the examples in NMEA2000 I get "failed to open CAN device".

However, if I use just the MCP2515 library I can get the MFD to send data with the queryOBD function.

Can you perhaps do me a favor and provide a binary data dump of some initial traffic? I would like to understand the NMEA data flow. It seems that a 59904 PGN needs to be sent every so often just to have the mfd (Raymarine) start sending data?

Would multiple devices on a network just see that a 59904 was being sent and not send their own, I guess what I am saying is why wouldn't broadcast be default?

A binary file of the first few thousand bytes between a "listener" and an MFD to just get some basic GPS data would be really helpful.

Thanks

Using library with Teensy based boards

I have tested ActisenseListener and TemperatureMonitor with Teensy 3.2 board by using Arduino IDE 1.82 and Teensyduino 1.36. For Teensy libraries one has to replace FlexCan code under "C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\FlexCAN" (or where ever you have it) with older FlexCan code, which you can find from http://www.kave.fi/Apps/Arduino/Teensy/FlexCAN.zip.

I'll report, if we find fix for latest FlexCan library.

Problem with pgn 127508 (battery)

I use the following code to send battery info to the network:

SetN2kPGN127508(msg, 0, 13.8, 0.8, N2kDoubleNA, sid++);

When converted in $PCDIN format, this is what it looks like:

$PCDIN,01F214,00000000,16,0064050800FFFF0C*5B

Which canalyzer translates as:

1969-12-31-16:00:00,0 0  22 255 127508 Battery Status:  Battery Instance = 0; Voltage = 13.80 V; Current = 0.8 A; SID = 12

However, the Raymarine i70 MFD refuses to display any battery information.

I now have access to iKommunicate and this is what it reports:

{
    "context": "vessels.urn:mrn:imo:mmsi:0",
    "updates": [{
        "source": {
            "type": "NMEA2000",
            "src": "1-22",
            "pgn": 127508,
            "label": "sources.N2000-01.022"
        },
        "timestamp": "2009-12-32T00:19:44Z",
        "values": [{
            "path": "electrical.batteries.8.voltage",
            "value": 13.799999
        }, {
            "path": "electrical.batteries.8.current",
            "value": 0.800000
        }]
    }]
}

Battery instance is always reported as 8. I have done tests with different values of BatteryInstance and always get the same result.

This could be a bug in iKommunicate but since the Raymarine also refused to display this battery voltage, I wonder if maybe there is a bug in the way NMEA2000 encodes this message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.