Skip to content

Commit

Permalink
Squashed 'lib/NMEA2000/' changes from 6835188..38d46ed
Browse files Browse the repository at this point in the history
38d46ed Compiler warning fixes
0d805a1 Fixes
3be0ec7 Arduino DUE CAN library update
605b6c3 Fix PGN 128259 send length to 8
a332640 Fixes and new features
c66e927 Merge pull request #62 from sarfata/do-not-override-esp8266-pgm-definitions
bd372f3 Merge pull request #63 from sarfata/bugfix/respond-to-query-sent-to-broadcast
61daf41 Fix a bug where we do not respond to info request sent to broadcast
2b31958 The Arduino framework for ESP8266 defines pgm_*

git-subtree-dir: lib/NMEA2000
git-subtree-split: 38d46ed67bbd72ddb2a58c2e83dbfb28fa0a979c
  • Loading branch information
sarfata committed Aug 10, 2017
1 parent 480933f commit 0e54564
Show file tree
Hide file tree
Showing 17 changed files with 1,189 additions and 245 deletions.
Binary file modified Documents/NMEA2000_library_reference.pdf
Binary file not shown.
107 changes: 107 additions & 0 deletions Examples/DeviceAnalyzer/DeviceAnalyzer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <Arduino.h>
#define N2k_CAN_INT_PIN 21
#include <NMEA2000_CAN.h> // This will automatically choose right CAN library and create suitable NMEA2000 object
#include "N2kDeviceList.h"

tN2kDeviceList *pN2kDeviceList;
Stream *OutputStream;

//*****************************************************************************
template<typename T> void PrintLabelValWithConversionCheckUnDef(const char* label, T val, double (*ConvFunc)(double val)=0, bool AddLf=false ) {
OutputStream->print(label);
if (!N2kIsNA(val)) {
if (ConvFunc) { OutputStream->print(ConvFunc(val)); } else { OutputStream->print(val); }
} else OutputStream->print("not available");
if (AddLf) OutputStream->println();
}

//*****************************************************************************
void setup() {
Serial.begin(115200);
OutputStream=&Serial;
Serial.println("Device analyzer is starting up...");
delay(3000);
NMEA2000.SetN2kCANReceiveFrameBufSize(150);
NMEA2000.SetN2kCANMsgBufSize(8);
// Set Product information
NMEA2000.SetProductInformation("00000003", // Manufacturer's Model serial code
100, // Manufacturer's product code
"N2k bus device analyzer", // Manufacturer's Model ID
"1.0.0.10 (2017-07-29)", // Manufacturer's Software version code
"1.0.0.0 (2017-07-12)" // Manufacturer's Model version
);

// Set device information
NMEA2000.SetDeviceInformation(2, // Unique number. Use e.g. Serial number.
130, // Device function=Display. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
120, // Device class=Display. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
2046 // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf
);
// Uncomment 3 rows below to see, what device will send to bus

NMEA2000.SetForwardStream(0); //&Serial);
NMEA2000.SetForwardType(tNMEA2000::fwdt_Text); // Show in clear text. Leave uncommented for default Actisense format.
// NMEA2000.SetForwardOwnMessages();

NMEA2000.EnableForward(false);
NMEA2000.SetMode(tNMEA2000::N2km_ListenAndNode, 50);
pN2kDeviceList = new tN2kDeviceList(&NMEA2000);
NMEA2000.Open();
Serial.println("Device analyzer started");
}

//*****************************************************************************
void PrintUlongList(const char *prefix, const unsigned long * List) {
uint8_t i;
if ( List!=0 ) {
Serial.print(prefix);
for (i=0; List[i]!=0; i++) {
if (i>0) Serial.print(", ");
Serial.print(List[i]);
}
Serial.println();
}
}

//*****************************************************************************
void PrintDevice(const tNMEA2000::tDevice *pDevice) {
if ( pDevice == 0 ) return;

Serial.println(pDevice->GetModelID());
Serial.print(" Source: "); Serial.println(pDevice->GetSource());
Serial.print(" Manufacturer code: "); Serial.println(pDevice->GetManufacturerCode());
Serial.print(" Unique number: "); Serial.println(pDevice->GetUniqueNumber());
Serial.print(" Software version: "); Serial.println(pDevice->GetSwCode());
Serial.print(" Model version: "); Serial.println(pDevice->GetModelVersion());
Serial.print(" Manufacturer Information: "); Serial.println(pDevice->GetManufacturerInformation());
PrintUlongList(" Transmit PGNs :",pDevice->GetTransmitPGNs());
PrintUlongList(" Receive PGNs :",pDevice->GetReceivePGNs());
Serial.println();
}

//*****************************************************************************
void ListDevices(bool force = false) {
if ( !force && !pN2kDeviceList->ReadResetIsListUpdated() ) return;

Serial.println();
Serial.println("**********************************************************************");
for (uint8_t i = 0; i < N2kMaxBusDevices; i++) PrintDevice(pN2kDeviceList->FindDeviceBySource(i));
}

//*****************************************************************************
void CheckCommand() {
if (Serial.available()) {
char chr = Serial.read();
switch ( chr ) {
case 'u': ListDevices(true); break;
}
}
}

//*****************************************************************************
void loop() {
NMEA2000.ParseMessages();
ListDevices();
CheckCommand();
}

32 changes: 21 additions & 11 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ functionality. See "Memory requirements" later.

To use Arduino Due board internal CAN you will also need NMEA2000_due library
and due_can library, which you can download from
https://github.com/collin80/due_can
https://github.com/ttlappalainen/due_can

To use Arduino boards with MCP2515 CAN bus controller, you will also need
NMEA2000_mcp library and mcp_can library. Use mcp_can library found on
Expand Down Expand Up @@ -61,6 +61,24 @@ I also thank for anybody who has extended library with new PGNs or processor
support.

== Changes ==
31.07.2017

- New versions of NMEA2000_due and due_can (see. https://github.com/ttlappalainen/due_can)

29.07.2017

- Fixed setting device instances on N2kGroupFunctionDefaultHandlers

- Fixed wind PGN 130306 output with reserved field.

- New abstract class tNEMA2000:tMsgHandler and functions AttachMsgHandler/DetachMsgHandler. With these you can have multiple
handlers. It also allow PGN specific handlers. See how it has been used on example DeviceAnalyzer. Other simple example
is under construction.

- New class tN2kDeviceList. See more on library reference and on example DeviceAnalyzer.

- Improved message type checking. This will be done for every message, so speed in important. For Arduino Mega average test time
was dropped from about 90 us to 9 us and for Teensy from 3.5 us to 0.9 us.

26.06.2017 Example updates

Expand Down Expand Up @@ -420,7 +438,7 @@ ready,

- Download either NMEA2000_due, NMEA2000_mcp or https://github.com/sarfata/NMEA2000_teensy[NMEA2000_teensy] library zip depending you hw.

- Download either https://github.com/collin80/due_can[due_can] or
- Download either https://github.com/ttlappalainen/due_can[due_can] or
https://github.com/ttlappalainen/CAN_BUS_Shield[mcp_can] library zip
depending you hw or install Teensyduino for Teensy 3.1/3.2 or 3.5/3.6 boards.

Expand Down Expand Up @@ -461,7 +479,7 @@ For use with Arduino due and due_can library

#include <N2kMsg.h>
#include <NMEA2000.h>
#include <due_can.h> // https://github.com/collin80/due_can
#include <due_can.h> // https://github.com/ttlappalainen/due_can
#include <NMEA2000_due.h>
tNMEA2000_due NMEA2000;

Expand Down Expand Up @@ -493,14 +511,6 @@ For use with Atmel AVR processors internal CAN controller

- https://www.nmea.org/Assets/20140102%20nmea-2000-126993%20heartbeat%20pgn%20corrigendum.pdf[Heartbeat PGN 126993]

== Running Tests ==

To run the unit tests, you must have `cmake` installed:

cmake .
cmake --build .
ctest .

== License ==

Copyright (c) 2015-2017 Timo Lappalainen, Kave Oy, www.kave.fi
Expand Down
3 changes: 3 additions & 0 deletions src/N2kDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ extern uint32_t millis();

// Declare PROGMEM macros to nothing on non-AVR targets.
#if !defined(__AVR__) && !defined(ARDUINO)
// ESP8266 provides it's own definition - Do not override it.
#if !defined(ARDUINO_ARCH_ESP8266)
#define PROGMEM
#define pgm_read_byte(var) *var
#define pgm_read_word(var) *var
#define pgm_read_dword(var) *var
#endif
#endif

// Definition for the F(str) macro. On Arduinos use what the framework
// provides to utilize the Stream class. On standard AVR8 we declare
Expand Down
Loading

0 comments on commit 0e54564

Please sign in to comment.