Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nmea2000 lib licenses #27

Merged
merged 6 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ separately.
- [i2c_t3](https://github.com/nox771/i2c_t3) is under the LGPL
- [ILI9341_t3](https://github.com/PaulStoffregen/ILI9341_t3) is under the MIT
license
- [NMEA2000](https://github.com/ttlappalainen/NMEA2000/) is under the LGPL
- [NMEA2000](https://github.com/ttlappalainen/NMEA2000/) is under the MIT
license
- [NMEA2000_teensy](https://github.com/sarfata/NMEA2000_teensy) is under the
LGPL
MIT license
- [Time](https://github.com/PaulStoffregen/Time) is under the LGPL
- [SdFat](https://github.com/greiman/SdFat) is under the GPL
- [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP) is under the LGPL
Expand Down
2 changes: 2 additions & 0 deletions lib/KBox/src/util/nmea2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
THE SOFTWARE.
*/

#include <stdlib.h>
#include <string.h>
#include "nmea2000.h"
#include "nmea.h"

Expand Down
4 changes: 2 additions & 2 deletions lib/KBox/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FRAMEWORK := $(HOME)/.platformio/packages/framework-arduinoteensy/cores/teensy3
CFLAGS := -g -Wall
CFLAGS := $(CFLAGS) -Iarduinomock/ -I$(FRAMEWORK) -I../../KBoxDebug/src
CFLAGS := $(CFLAGS) -I../../List/src -I../../NMEA2000 -I../src
CPPFLAGS := $(CFLAGS) -std=c++11
CPPFLAGS := $(CFLAGS) -std=c++11 -DARDUINO

# Transformation rules for C and CPP files
%.o: %.cpp Makefile
Expand Down Expand Up @@ -49,7 +49,7 @@ NMEASentenceBuilderTest: NMEASentenceBuilderTest.o ../src/util/NMEASentenceBuild
$(CXX) $(CFLAGS) -o $@ $^

# Test the visitor that converts KMessage into NMEA
KMessageNMEAVisitorTest: KMessageNMEAVisitorTest.o ../src/util/NMEASentenceBuilder.o ../src/KMessage.o ../src/util/nmea.o ../src/util/nmea2000.o ../src/KMessageNMEAVisitor.o ../../NMEA2000/N2kMsg.o $(TEST_DEPS)
KMessageNMEAVisitorTest: KMessageNMEAVisitorTest.o ../src/util/NMEASentenceBuilder.o ../src/KMessage.o ../src/util/nmea.o ../src/util/nmea2000.o ../src/KMessageNMEAVisitor.o ../../NMEA2000/N2kMsg.o ../../NMEA2000/N2kStream.cpp $(TEST_DEPS)
$(CXX) $(CFLAGS) -o $@ $^

clean:
Expand Down
68 changes: 35 additions & 33 deletions lib/NMEA2000/ActisenseReader.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
/*
/*
ActisenseReader.cpp
2015 Copyright (c) Kave Oy, www.kave.fi All right reserved.
Copyright (c) 2015-2017 Timo Lappalainen, Kave Oy, www.kave.fi
Author: Timo Lappalainen
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:
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
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.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
1301 USA
This is class for reading Actisense format messages from given stream.
*/
#include <ActisenseReader.h>
#include "ActisenseReader.h"
#include <string.h>

//*****************************************************************************
tActisenseReader::tActisenseReader() {
Expand All @@ -43,10 +44,10 @@ void tActisenseReader::ClearBuffer() {
//*****************************************************************************
bool tActisenseReader::AddByteToBuffer(char NewByte) {
if (MsgWritePos>=MAX_STREAM_MSG_BUF_LEN) return false;

MsgBuf[MsgWritePos]=NewByte;
MsgWritePos++;
if ( MsgBuf[1]+3!=MsgWritePos ) byteSum+=NewByte; // !Do not add CRC to byteSum
if ( MsgBuf[1]+3!=MsgWritePos ) byteSum+=NewByte; // !Do not add CRC to byteSum
return true;
}

Expand All @@ -57,14 +58,14 @@ bool tActisenseReader::AddByteToBuffer(char NewByte) {

//*****************************************************************************
bool tActisenseReader::CheckMessage(tN2kMsg &N2kMsg) {

N2kMsg.Clear();

if (MsgWritePos!=MsgBuf[1]+3) {
return false; // Length does not match. Add type, length and crc
}
byte CheckSum = (byte)((byteSum == 0) ? 0 : (256 - byteSum));

uint8_t CheckSum = (uint8_t)((byteSum == 0) ? 0 : (256 - byteSum));
if ( CheckSum!=MsgBuf[MsgWritePos-1] ) {
return false; // Checksum does not match
}
Expand All @@ -80,24 +81,25 @@ bool tActisenseReader::CheckMessage(tN2kMsg &N2kMsg) {
memcpy(&(N2kMsg.MsgTime), &(MsgBuf[8]), 4);
N2kMsg.DataLen=MsgBuf[12];
for (int i=13, j=0; i<MsgWritePos-1; i++, j++) N2kMsg.Data[j]=MsgBuf[i];

return true;
}

//*****************************************************************************
// Read Actisense formatted NMEA2000 message from stream
// Read Actisense formatted NMEA2000 message from stream
// Actisense Format:
// <10><02><93><length (1)><priority (1)><PGN (3)><destination (1)><source (1)><time (4)><len (1)><data (len)><CRC (1)><10><03>
bool tActisenseReader::GetMessageFromStream(tN2kMsg &N2kMsg) {
bool result=false;

if (ReadStream==0) return false;

while (ReadStream->available() > 0 && !result) {
int NewByte=ReadStream->read();
if (ReadStream==0)
return false;

int NewByte;
while ((NewByte = ReadStream->read()) != -1 && !result) {
// Serial.println((char)NewByte,HEX);
if (MsgIsComing) {
if (EscapeReceived) {
if (EscapeReceived) {
switch (NewByte) {
case Escape: // Escaped Escape
EscapeReceived=false;
Expand All @@ -120,7 +122,7 @@ bool tActisenseReader::GetMessageFromStream(tN2kMsg &N2kMsg) {
default: // Error
ClearBuffer();
}
} else {
} else {
if (NewByte==Escape) {
EscapeReceived=true;
} else {
Expand All @@ -146,14 +148,14 @@ bool tActisenseReader::GetMessageFromStream(tN2kMsg &N2kMsg) {
EscapeReceived=(NewByte==Escape);
}
}

return result;
}

//*****************************************************************************
void tActisenseReader::ParseMessages() {
tN2kMsg N2kMsg;

while (GetMessageFromStream(N2kMsg)) {
if (MsgHandler!=0) MsgHandler(N2kMsg);
}
Expand Down
50 changes: 26 additions & 24 deletions lib/NMEA2000/ActisenseReader.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/*
/*
ActisenseReader.h
2015 Copyright (c) Kave Oy, www.kave.fi All right reserved.
Copyright (c) 2015-2017 Timo Lappalainen, Kave Oy, www.kave.fi
Author: Timo Lappalainen
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:
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
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.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
1301 USA
This is class for reading Actisense format messages from given stream.
There is unresolved problem to use programming port with reading data.
Expand All @@ -29,7 +29,9 @@ USB port there is no problem.
*/
#ifndef _ACTISENSE_READER_H_
#define _ACTISENSE_READER_H_
#include <N2kMsg.h>

#include "N2kMsg.h"
#include "N2kStream.h"

class tActisenseReader
{
Expand All @@ -42,26 +44,26 @@ class tActisenseReader
// Buffer for incoming messages from stream
unsigned char MsgBuf[MAX_STREAM_MSG_BUF_LEN];
int MsgWritePos;

protected:
Stream* ReadStream;
N2kStream* ReadStream;
// Handler callback
void (*MsgHandler)(const tN2kMsg &N2kMsg);

protected:
bool AddByteToBuffer(char NewByte);
void ClearBuffer();
bool CheckMessage(tN2kMsg &N2kMsg);

public:
tActisenseReader();
// Set stream, which would be used for reading messages. You have to
// open stream first, so e.g. for SerialUSB call begin first.
void SetReadStream(Stream* _stream) { ReadStream=_stream; }
void SetReadStream(N2kStream* _stream) { ReadStream=_stream; }

// You can either call this or ParseMessages periodically.
bool GetMessageFromStream(tN2kMsg &N2kMsg);

// Set message handler with SetMsgHandler and then call this periodically or use GetMessageFromStream
void ParseMessages();
// Set message handler to be used in ParseMessages, when message has been received.
Expand Down
Binary file modified lib/NMEA2000/Documents/NMEA2000_library_reference.pdf
Binary file not shown.
36 changes: 22 additions & 14 deletions lib/NMEA2000/Examples/MessageSender/MessageSender.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Demo: NMEA2000 library. Send main cabin temperature to the bus.
// Demo: NMEA2000 library. Send different NMEA 2000 messages as example to the bus.

#include <Arduino.h>
#include <NMEA2000_CAN.h> // This will automatically choose right CAN library and create suitable NMEA2000 object
Expand All @@ -8,14 +8,14 @@ void setup() {
// Set Product information
NMEA2000.SetProductInformation("00000001", // Manufacturer's Model serial code
100, // Manufacturer's product code
"Simple temp monitor", // Manufacturer's Model ID
"1.0.0.11 (2015-08-03)", // Manufacturer's Software version code
"1.0.0.0 (2015-08-03)" // Manufacturer's Model version
"Message sender example", // Manufacturer's Model ID
"1.0.0.15 (2017-01-01)", // Manufacturer's Software version code
"1.0.0.0 (2017-01-01)" // Manufacturer's Model version
);
// Det device information
// Set device information
NMEA2000.SetDeviceInformation(1, // Unique number. Use e.g. Serial number.
130, // Device function=Temperature. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
75, // Device class=Sensor Communication Interface. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
132, // Device function=Analog to NMEA 2000 Gateway. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20&%20function%20codes%20v%202.00.pdf
25, // Device class=Inter/Intranetwork Device. 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
Expand Down Expand Up @@ -51,6 +51,8 @@ double ReadWaterTemp() {
void SendN2kSlowData() {
static unsigned long SlowDataUpdated=millis();
tN2kMsg N2kMsg;
static double Heading=127.5;

// !delay is not good practise withing loops! I use it in this sample since
// I tested Arduino Mega as receiver without inteerupt and it could not handle all messages
// send without delay. With interrupt, it can do it and you can set DelayBetweenSend to 0.
Expand All @@ -61,8 +63,10 @@ void SendN2kSlowData() {

SetN2kDCBatStatus(N2kMsg, 1, 12.72);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kDCBatStatus(N2kMsg, 0, 12.45, 5.08, CToKelvin(27.15));

static unsigned char sid=0;
// SetN2kDCBatStatus(N2kMsg, 0, 12.45, 5.08, CToKelvin(27.15));
SetN2kPGN127508(N2kMsg, 0, 13.8, 0.95, N2kDoubleNA, sid++);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kTemperatureExt(N2kMsg, 1, 1, N2kts_MainCabinTemperature, ReadCabinTemp(),CToKelvin(21.6));
Expand All @@ -86,21 +90,25 @@ void SendN2kSlowData() {
SetN2kAttitude(N2kMsg,1,DegToRad(-3.1),DegToRad(2.4),DegToRad(-7.8));
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kEngineDynamicParam(N2kMsg,1,656000,CToKelvin(86.3),CToKelvin(82.1),14.21,5.67,hToSeconds(2137.55),N2kDoubleNA,N2kDoubleNA,N2kInt8NA,N2kInt8NA,true);
SetN2kEngineDynamicParam(N2kMsg,0,656000,CToKelvin(86.3),CToKelvin(82.1),14.21,5.67,hToSeconds(2137.55),N2kDoubleNA,N2kDoubleNA,N2kInt8NA,N2kInt8NA,true);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kTransmissionParameters(N2kMsg,1,N2kTG_Forward,750000, CToKelvin(65.5),true,false,true);
SetN2kTransmissionParameters(N2kMsg,0,N2kTG_Forward,750000, CToKelvin(65.5),true,false,true);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kSystemTime(N2kMsg,1,17555,62000);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);

SetN2kGNSS(N2kMsg,1,17555,62000,-60.1,67.5,10.5,N2kGNSSt_GPS,N2kGNSSm_GNSSfix,12,0.8,0.5,15,1,N2kGNSSt_GPS,15,2);
SetN2kGNSS(N2kMsg,1,17555,62000,60.1,22.5,10.5,N2kGNSSt_GPS,N2kGNSSm_GNSSfix,12,0.8,0.5,15,1,N2kGNSSt_GPS,15,2);
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);
// Serial.print(millis()); Serial.println(", Temperature send ready");

SetN2kMagneticHeading(N2kMsg, 0, DegToRad(127.5), DegToRad(0.0), DegToRad(7.5));
SetN2kMagneticHeading(N2kMsg, 0, DegToRad(Heading), DegToRad(0.0), DegToRad(5.5));
delay(DelayBetweenSend); NMEA2000.SendMsg(N2kMsg);
//Heading+=1; if (Heading>=360.0 ) Heading-=360.0;

SetN2kAISClassAPosition(N2kMsg, 1, tN2kAISRepeat::N2kaisr_First, 123456789, 26.396, -80.075, 1, 1, 1, 20, 20, 30, 0, tN2kAISNavStatus::N2kaisns_At_Anchor);
NMEA2000.SendMsg(N2kMsg);
}
}

Expand All @@ -112,7 +120,7 @@ void SendN2kRapidData() {

if ( RapidDataUpdated+RapidDataUpdatePeriod<millis() ) {
RapidDataUpdated=millis();
SetN2kEngineParamRapid(N2kMsg,1,4350); //,820000,48);
SetN2kEngineParamRapid(N2kMsg,0,4350); //,820000,48);
NMEA2000.SendMsg(N2kMsg);
SetN2kCOGSOGRapid(N2kMsg,1,N2khr_true,DegToRad(115.6),0.1);
NMEA2000.SendMsg(N2kMsg);
Expand Down
Loading