common

package
v0.0.0-...-e66aca5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package common contains utilities useful across multiple CANboat tools.

Index

Constants

View Source
const (
	FastPacketIndex         = 0
	FastPacketSize          = 1
	FastPacketBucket0Size   = 6
	FastPacketBucketNSize   = 7
	FastPacketBucket0Offset = 2
	FastPacketBucketNOffset = 1
	FastPacketMaxIndex      = 0x1f
	FastPacketMaxSize       = FastPacketBucket0Size + FastPacketBucketNSize*FastPacketMaxIndex
)

FastPacket constants.

View Source
const (
	CANBoatPGNStart = 0x40000
	CANBoatPGNEnd   = 0x401FF
	ActisenseBEM    = 0x40000 /* Actisense specific fake PGNs */
	IKnovertBEM     = 0x40100 /* iKonvert specific fake PGNs */
)

* The 'converter' programs generate fake PGNs containing data that they generate * themselves or via proprietary non-PGN serial messages. * These need unique fake PGNs.

View Source
const (
	Version       = "5.0.3"
	SchemaVersion = "2.1.0"
)

Version constants.

View Source
const Copyright = "CANboat version v" + Version + "\n\n" +
	"(C) 2009-2023, Kees Verruijt, Harlingen, The Netherlands.\n" +
	"For more information see https://github.com/canboat/canboat\n" +
	"\n" + License + "\n"

Copyright is the ORIGINAL CANBOT version.

View Source
const License = "This file is part of CANboat.\n" +
	"\n" +
	"Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
	"you may not use this file except in compliance with the License.\n" +
	"You may obtain a copy of the License at\n" +
	"\n" +
	"    http://www.apache.org/licenses/LICENSE-2.0\n" +
	"\n" +
	"Unless required by applicable law or agreed to in writing, software\n" +
	"distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
	"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
	"See the License for the specific language governing permissions and\n" +
	"limitations under the License.\n"

License is the ORIGINAL CANBOT license.

Variables

This section is empty.

Functions

func AllowPGNFastPacket

func AllowPGNFastPacket(n uint32) bool

AllowPGNFastPacket returns if this PGN Fast is allowed.

func AllowPGNSingleFrame

func AllowPGNSingleFrame(n uint32) bool

AllowPGNSingleFrame returns if this PGN can be in a single frame.

func Max

func Max[T cmp.Ordered](x, y T) T

Max returns the max of x,y.

func Min

func Min[T cmp.Ordered](x, y T) T

Min returns the min of x,y.

func ParseRawFormatActisenseN2KAscii

func ParseRawFormatActisenseN2KAscii(msg []byte, m *RawMessage, showJSON bool, logger *Logger) int

ParseRawFormatActisenseN2KAscii parses Actisense N2K ASCII messages.

func ParseRawFormatAirmar

func ParseRawFormatAirmar(msg []byte, m *RawMessage, showJSON bool, logger *Logger) int

ParseRawFormatAirmar parses Airmar messages. Note(UNTESTED): See README.md.

func ParseRawFormatChetco

func ParseRawFormatChetco(msg []byte, m *RawMessage, showJSON bool, logger *Logger) int

ParseRawFormatChetco parses Chetco messages. Note(UNTESTED): See README.md.

func ParseRawFormatFast

func ParseRawFormatFast(msg []byte, m *RawMessage, showJSON bool, logger *Logger) int

ParseRawFormatFast parses FAST messages.

func ParseRawFormatGarminCSV

func ParseRawFormatGarminCSV(msg []byte, m *RawMessage, showJSON, absolute bool, logger *Logger) int

ParseRawFormatGarminCSV parses Garmin CSV (1 and 2) messages.

Sequence #,Timestamp,PGN,Name,Manufacturer,Remote Address,Local Address,Priority,Single Frame,Size,Packet 0,486942,127508,Battery Status,Garmin,6,255,2,1,8,0x017505FF7FFFFFFF 129,491183,129029,GNSS Position Data,Unknown Manufacturer,3,255,3,0,43,0xFFDF40A6E9BB22C04B3666C18FBF0600A6C33CA5F84B01A0293B140000000010FC01AC26AC264A12000000

Note(UNTESTED): See README.md.

func ParseRawFormatNavLink2

func ParseRawFormatNavLink2(msg []byte, m *RawMessage, logger *Logger) int

ParseRawFormatNavLink2 parses Digital Yacht NavLink 2 messages. https://github.com/digitalyacht/iKonvert/wiki/4.-Serial-Protocol#41-rx-pgn-sentence !PDGY,<pgn#>,p,src,dst,timer,<pgn_data> CR LF

Key

<pgn#> = NMEA2000 PGN number between 0 and 999999

p = Priority 0-7 with 0 being highest and 7 lowest

src = Source Address of the device sending the PGN between 0-251

dst = Destination Address of the device receiving the PGN between 0-255 (255 = global)

timer = internal timer of the gateway in milliseconds 0-999999

<pgn_data> = The binary payload of the PGN encoded in Base64.

func ParseRawFormatPlain

func ParseRawFormatPlain(msg []byte, m *RawMessage, showJSON bool, logger *Logger) int

ParseRawFormatPlain parses PLAIN messages.

func ParseRawFormatYDWG02

func ParseRawFormatYDWG02(msg []byte, m *RawMessage, logger *Logger) int

ParseRawFormatYDWG02 parses YDWG-02 messages.

Yacht Digital, YDWG-02

Example output: 00:17:55.475 R 0DF50B23 FF FF FF FF FF 00 00 FF

Example usage:

pi@yacht:~/canboat/analyzer $ netcat 192.168.3.2 1457 | analyzer -json INFO 2018-10-16T09:57:39.665Z [analyzer] Detected YDWG-02 protocol with all data on one line INFO 2018-10-16T09:57:39.665Z [analyzer] New PGN 128267 for device 35 (heap 5055 bytes) {"timestamp":"2018-10-16T22:25:25.166","prio":3,"src":35,"dst":255,"pgn":128267,"description":"Water Depth","fields":{"Offset":0.000}} INFO 2018-10-16T09:57:39.665Z [analyzer] New PGN 128259 for device 35 (heap 5070 bytes) {"timestamp":"2018-10-16T22:25:25.177","prio":2,"src":35,"dst":255,"pgn":128259,"description":"Speed","fields":{"Speed Water Referenced":0.00,"Speed Water Referenced Type":"Paddle wheel"}} INFO 2018-10-16T09:57:39.666Z [analyzer] New PGN 128275 for device 35 (heap 5091 bytes) {"timestamp":"2018-10-16T22:25:25.179","prio":6,"src":35,"dst":255,"pgn":128275,"description":"Distance Log","fields":{"Date":"1980.05.04"}} INFO 2018-10-16T09:57:39.666Z [analyzer] New PGN 130311 for device 35 (heap 5106 bytes) {"timestamp":"2018-10-16T22:25:25.181","prio":5,"src":35,"dst":255,"pgn":130311,"description":"Environmental Parameters","fields":{"Temperature Source":"Sea Temperature","Temperature":13.39}} {"timestamp":"2018-10-16T22:25:25.181","prio":6,"src":35,"dst":255,"pgn":128275,"description":"Distance Log","fields":{"Date":"2006.11.06", "Time": "114:38:39.07076","Log":1940}} {"timestamp":"2018-10-16T22:25:25.185","prio":6,"src":35,"dst":255,"pgn":128275,"description":"Distance Log","fields":{"Date":"1970.07.14"}} INFO 2018-10-16T09:57:39.666Z [analyzer] New PGN 130316 for device 35 (heap 5121 bytes) {"timestamp":"2018-10-16T22:25:25.482","prio":5,"src":35,"dst":255,"pgn":130316,"description":"Temperature Extended Range","fields":{"Instance":0,"Source":"Sea Temperature","Temperature":13.40}} {"timestamp":"2018-10-16T22:25:25.683","prio":5,"src":35,"dst":255,"pgn":130311,"description":"Environmental Parameters","fields":{"Temperature Source":"Sea Temperature","Temperature":13.39}}

Note(UNTESTED): See README.md.

Types

type ExitError

type ExitError struct {
	Code  int
	Cause error
}

ExitError is an error for exit codes.

func (ExitError) Error

func (e ExitError) Error() string

Error returns the underlying error and cause.

func (ExitError) Unwrap

func (e ExitError) Unwrap() error

Unwrap returns the cause, if present.

type LogLevel

type LogLevel int

LogLevel represents a level to log at.

const (
	LogLevelFatal LogLevel = iota
	LogLevelError
	LogLevelInfo
	LogLevelDebug
)

All log levels.

func (LogLevel) String

func (l LogLevel) String() string

String returns the human readable LogLevel.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is for logging.

func NewLogger

func NewLogger(writer io.Writer) *Logger

NewLogger returns a new logger.

func NewLoggerForCLI

func NewLoggerForCLI(writer io.Writer) *Logger

NewLoggerForCLI returns a new logger for use by a CLI.

func (*Logger) Abort

func (l *Logger) Abort(format string, v ...any) error

Abort logs a message at the FATAL level. The returned error may be used to propagate upwards and if running as a CLI, it may os.Exit.

func (*Logger) Debug

func (l *Logger) Debug(format string, v ...any)

Debug logs a message at the DEBUG level.

func (*Logger) Error

func (l *Logger) Error(format string, v ...any) error

Error logs a message at the ERROR level. The returned error may be used to propagate upwards.

func (*Logger) Info

func (l *Logger) Info(format string, v ...any)

Info logs a message at the INFO level.

func (*Logger) Now

func (l *Logger) Now() time.Time

Now returns the current time.Time as seen by the logger.

func (*Logger) SetFixedTimestamp

func (l *Logger) SetFixedTimestamp(fixedStr string)

SetFixedTimestamp sets a fixed timestamp for logs.

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(level LogLevel)

SetLogLevel sets the logger's log level.

func (*Logger) SetProgName

func (l *Logger) SetProgName(name string)

SetProgName sets the program name running this logger (used by CLI).

type Message

type Message struct {
	Timestamp   string                 `json:"timestamp"`
	Priority    int                    `json:"prio"`
	Src         int                    `json:"src"`
	Dst         int                    `json:"dst"`
	Pgn         int                    `json:"pgn"`
	Description string                 `json:"description"`
	Fields      map[string]interface{} `json:"fields"`
}

Message is a NMEA 2000 PGN message.

type RawMessage

type RawMessage struct {
	Timestamp string
	Prio      uint8
	PGN       uint32
	Dst       uint8
	Src       uint8
	Len       uint8
	Data      [FastPacketMaxSize]byte
}

RawMessage is a raw NMEA 2000 PGN message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL