common

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDataLength = 8

Variables

This section is empty.

Functions

func CheckBitRangeBigEndian

func CheckBitRangeBigEndian(frameLength, rangeStart, rangeLength uint8) error

CheckBitRangeBigEndian checks that a big-endian bit range fits in the data.

func CheckBitRangeLittleEndian

func CheckBitRangeLittleEndian(frameLength, rangeStart, rangeLength uint8) error

CheckBitRangeLittleEndian checks that a little-endian bit range fits in the data.

func CheckValue

func CheckValue(value uint64, bits uint8) error

CheckValue checks that a value fits in a number of bits.

Types

type Data

type Data [MaxDataLength]byte

Data holds the data in a CAN frame.

Layout

Individual bits in the data are numbered according to the following scheme:

         BIT
         NUMBER
         +------+------+------+------+------+------+------+------+
         |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
BYTE     +------+------+------+------+------+------+------+------+
NUMBER
+-----+  +------+------+------+------+------+------+------+------+
|  0  |  |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
+-----+  +------+------+------+------+------+------+------+------+
|  1  |  |  15  |  14  |  13  |  12  |  11  |  10  |   9  |   8  |
+-----+  +------+------+------+------+------+------+------+------+
|  2  |  |  23  |  22  |  21  |  20  |  19  |  18  |  17  |  16  |
+-----+  +------+------+------+------+------+------+------+------+
|  3  |  |  31  |  30  |  29  |  28  |  27  |  26  |  25  |  24  |
+-----+  +------+------+------+------+------+------+------+------+
|  4  |  |  39  |  38  |  37  |  36  |  35  |  34  |  33  |  32  |
+-----+  +------+------+------+------+------+------+------+------+
|  5  |  |  47  |  46  |  45  |  44  |  43  |  42  |  41  |  40  |
+-----+  +------+------+------+------+------+------+------+------+
|  6  |  |  55  |  54  |  53  |  52  |  51  |  50  |  49  |  48  |
+-----+  +------+------+------+------+------+------+------+------+
|  7  |  |  63  |  62  |  61  |  60  |  59  |  58  |  57  |  56  |
+-----+  +------+------+------+------+------+------+------+------+

Bit ranges can be manipulated using little-endian and big-endian bit ordering.

Little-endian bit ranges

Example range of length 32 starting at bit 29:

         BIT
         NUMBER
         +------+------+------+------+------+------+------+------+
         |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
BYTE     +------+------+------+------+------+------+------+------+
NUMBER
+-----+  +------+------+------+------+------+------+------+------+
|  0  |  |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
+-----+  +------+------+------+------+------+------+------+------+
|  1  |  |  15  |  14  |  13  |  12  |  11  |  10  |   9  |   8  |
+-----+  +------+------+------+------+------+------+------+------+
|  2  |  |  23  |  22  |  21  |  20  |  19  |  18  |  17  |  16  |
+-----+  +------+------+------+------+------+------+------+------+
|  3  |  |  <-------------LSb |  28  |  27  |  26  |  25  |  24  |
+-----+  +------+------+------+------+------+------+------+------+
|  4  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  5  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  6  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  7  |  |  63  |  62  |  61  | <-MSb--------------------------- |
+-----+  +------+------+------+------+------+------+------+------+

Big-endian bit ranges

Example range of length 32 starting at bit 29:

         BIT
         NUMBER
         +------+------+------+------+------+------+------+------+
         |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
BYTE     +------+------+------+------+------+------+------+------+
NUMBER
+-----+  +------+------+------+------+------+------+------+------+
|  0  |  |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
+-----+  +------+------+------+------+------+------+------+------+
|  1  |  |  15  |  14  |  13  |  12  |  11  |  10  |   9  |   8  |
+-----+  +------+------+------+------+------+------+------+------+
|  2  |  |  23  |  22  |  21  |  20  |  19  |  18  |  17  |  16  |
+-----+  +------+------+------+------+------+------+------+------+
|  3  |  |  31  |  30  | <-MSb---------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  4  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  5  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  6  |  |  <--------------------------------------------------  |
+-----+  +------+------+------+------+------+------+------+------+
|  7  |  |  <------LSb |  61  |  60  |  59  |  58  |  57  |  56  |
+-----+  +------+------+------+------+------+------+------+------+

func (*Data) Bit

func (d *Data) Bit(i uint8) bool

Bit returns the value of the i:th bit in the data as a bool.

func (*Data) PackBigEndian

func (d *Data) PackBigEndian() uint64

PackBigEndian packs the data into a contiguous uint64 value for big-endian signals.

func (*Data) PackLittleEndian

func (d *Data) PackLittleEndian() uint64

PackLittleEndian packs the data into a contiguous uint64 value for little-endian signals.

func (*Data) SetBit

func (d *Data) SetBit(i uint8, value bool)

SetBit sets the value of the i:th bit in the data.

func (*Data) SetSignedBitsBigEndian

func (d *Data) SetSignedBitsBigEndian(start, length uint8, value int64)

SetSignedBitsBigEndian sets the big-endian bit range [start, start+length) to the provided signed value.

func (*Data) SetSignedBitsLittleEndian

func (d *Data) SetSignedBitsLittleEndian(start, length uint8, value int64)

SetSignedBitsLittleEndian sets the little-endian bit range [start, start+length) to the provided signed value.

func (*Data) SetUnsignedBitsBigEndian

func (d *Data) SetUnsignedBitsBigEndian(start, length uint8, value uint64)

SetUnsignedBitsBigEndian sets the big-endian bit range [start, start+length) to the provided unsigned value.

func (*Data) SetUnsignedBitsLittleEndian

func (d *Data) SetUnsignedBitsLittleEndian(start, length uint8, value uint64)

SetUnsignedBitsBigEndian sets the little-endian bit range [start, start+length) to the provided unsigned value.

func (*Data) SignedBitsBigEndian

func (d *Data) SignedBitsBigEndian(start, length uint8) int64

SignedBitsBigEndian returns little-endian bit range [start, start+length) as a signed value.

func (*Data) SignedBitsLittleEndian

func (d *Data) SignedBitsLittleEndian(start, length uint8) int64

SignedBitsLittleEndian returns little-endian bit range [start, start+length) as a signed value.

func (*Data) UnpackBigEndian

func (d *Data) UnpackBigEndian(packed uint64)

UnpackBigEndian sets the value of d.Bytes by unpacking the provided value as sequential big-endian bits.

func (*Data) UnpackLittleEndian

func (d *Data) UnpackLittleEndian(packed uint64)

UnpackLittleEndian sets the value of d.Bytes by unpacking the provided value as sequential little-endian bits.

func (*Data) UnsignedBitsBigEndian

func (d *Data) UnsignedBitsBigEndian(start, length uint8) uint64

UnsignedBitsBigEndian returns the big-endian bit range [start, start+length) as an unsigned value.

func (*Data) UnsignedBitsLittleEndian

func (d *Data) UnsignedBitsLittleEndian(start, length uint8) uint64

UnsignedBitsLittleEndian returns the little-endian bit range [start, start+length) as an unsigned value.

Jump to

Keyboard shortcuts

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