Documentation ¶
Overview ¶
Package common contains utilities useful across multiple CANboat tools.
Index ¶
- Constants
- Variables
- func AllowPGNFastPacket(n uint32) bool
- func AllowPGNSingleFrame(n uint32) bool
- func DataLengthInPlainOrFast(msg []byte, logger logging.Logger) (int, bool)
- func GetCanIDFromISO11783Bits(prio uint8, pgn uint32, src, dst uint8) int
- func GetISO11783BitsFromCanID(id uint) (uint8, uint32, uint8, uint8)
- func MarshalRawMessageToFastFormat(rawMsg *RawMessage, multi MultiPackets) ([]byte, error)
- func MarshalRawMessageToPlainFormat(rawMsg *RawMessage, multi MultiPackets) ([]byte, error)
- func Max[T cmp.Ordered](x, y T) T
- func Min[T cmp.Ordered](x, y T) T
- func NewLogger(writer io.Writer) logging.Logger
- func Now() time.Time
- func ParseRawFormatActisenseN2KAscii(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatAirmar(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatChetco(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatFast(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatGarminCSV(msg []byte, m *RawMessage, absolute bool, logger logging.Logger) int
- func ParseRawFormatNavLink2(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatPlain(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseRawFormatYDWG02(msg []byte, m *RawMessage, logger logging.Logger) int
- func ParseTimestamp(from string) (time.Time, error)
- type ExitError
- type FieldVariable
- type FixedClock
- type Message
- type MultiPackets
- type RawMessage
Constants ¶
const ( FastPacketIndex = 0 FastPacketSize = 1 FastPacketBucket0Size = 6 FastPacketBucketNSize = 7 FastPacketBucket0Offset = 2 FastPacketBucketNOffset = 1 FastPacketMaxIndex = 0x1f FastPacketMaxSize = FastPacketBucket0Size + FastPacketBucketNSize*FastPacketMaxIndex )
FastPacket constants.
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.
const ( Version = "5.0.3" SchemaVersion = "2.1.0" )
Version constants.
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.
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 ¶
var UseFixedTimestamp atomic.Bool
UseFixedTimestamp is for testing purposes only.
Functions ¶
func AllowPGNFastPacket ¶
AllowPGNFastPacket returns if this PGN Fast is allowed.
func AllowPGNSingleFrame ¶
AllowPGNSingleFrame returns if this PGN can be in a single frame.
func DataLengthInPlainOrFast ¶
func GetISO11783BitsFromCanID ¶
var prio, src, dst uint8 var pgn uint32
prio, pgn, src, dst := GetISO11783BitsFromCanID(id)
return prio, pgn, src, dst.
func MarshalRawMessageToFastFormat ¶
func MarshalRawMessageToFastFormat(rawMsg *RawMessage, multi MultiPackets) ([]byte, error)
MarshalRawMessageToFastFormat marshals a RawMessage to the FAST packet format, described below. If the data is larger than 8 bytes, it will be split across multiple packets up to 223 bytes.
1 2 3 4 5 6 7 2022-09-28-11:36:59.668,3,129029,0,255,8,00,2f,e7,95,3d,00,73,d6
1. Timestamp 2. Priority 3. PGN 4. Source 5. Destination 6. Data Length 7. Data.
func MarshalRawMessageToPlainFormat ¶
func MarshalRawMessageToPlainFormat(rawMsg *RawMessage, multi MultiPackets) ([]byte, error)
MarshalRawMessageToPlainFormat marshals a RawMessage to the PLAIN packet format, described below.
1 2 3 4 5 6 7 2022-09-10T12:10:16.614Z,6,60928,5,255,8,fb,9b,70,22,00,9b,50,c0
1. Timestamp 2. Priority 3. PGN 4. Source 5. Destination 6. Data Length 7. Data.
func ParseRawFormatActisenseN2KAscii ¶
func ParseRawFormatActisenseN2KAscii(msg []byte, m *RawMessage, logger logging.Logger) int
ParseRawFormatActisenseN2KAscii parses Actisense N2K ASCII messages.
func ParseRawFormatAirmar ¶
func ParseRawFormatAirmar(msg []byte, m *RawMessage, logger logging.Logger) int
ParseRawFormatAirmar parses Airmar messages. Note(UNTESTED): See README.md.
func ParseRawFormatChetco ¶
func ParseRawFormatChetco(msg []byte, m *RawMessage, logger logging.Logger) int
ParseRawFormatChetco parses Chetco messages. Note(UNTESTED): See README.md.
func ParseRawFormatFast ¶
func ParseRawFormatFast(msg []byte, m *RawMessage, logger logging.Logger) int
ParseRawFormatFast parses FAST messages.
func ParseRawFormatGarminCSV ¶
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 logging.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, logger logging.Logger) int
ParseRawFormatPlain parses PLAIN messages.
func ParseRawFormatYDWG02 ¶
func ParseRawFormatYDWG02(msg []byte, m *RawMessage, logger logging.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 ¶
ExitError is an error for exit codes.
type FieldVariable ¶
FieldVariable represents a reference to a PGN field at a particular value.
type FixedClock ¶
type FixedClock struct{}
FixedClock is used to return fixed time.
type Message ¶
type Message struct { // if relative, then it's from January 1, year 1, 00:00:00.000000000 UTC Timestamp time.Time `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"` Sequence uint8 `json:"-"` // 3 bits max, unvalidated CachedRawData []byte `json:"-"` }
Message is a NMEA 2000 PGN message.
type MultiPackets ¶
type MultiPackets byte
const ( MultiPacketsSeparate MultiPackets = iota MultiPacketsCoalesced )
func (MultiPackets) String ¶
func (multi MultiPackets) String() string
type RawMessage ¶
type RawMessage struct { // if relative, then it's from January 1, year 1, 00:00:00.000000000 UTC Timestamp time.Time Prio uint8 PGN uint32 Dst uint8 Src uint8 Len uint8 Data []byte // Only set when this is a fast packet Sequence uint8 // 3 bits max, unvalidated Frame uint8 // 5 bits max, unvalidated }
RawMessage is a raw NMEA 2000 PGN message.
func (*RawMessage) SeparateFastPackets ¶
func (rm *RawMessage) SeparateFastPackets() ([]*RawMessage, error)
func (*RawMessage) SeparateSingleOrFastPackets ¶
func (rm *RawMessage) SeparateSingleOrFastPackets(isFastPacket bool) ([]*RawMessage, error)