@yinyinfurong_zmr/dbc-can
Version:
A general purpose CAN (Controller Area Network) toolbox with support for .dbc file parsing, CAN message decoding, and more
61 lines (60 loc) • 2.37 kB
TypeScript
import { EndianType } from '../shared/DataTypes';
declare class BitUtils {
/**
* Returns a boolean value indicating whether the provided CAN id is extended or standard
* @param id Number
* @protected
*/
isIdExtended(id: number): boolean;
/**
* Sets the extended flag in the provided ID and returns the new CAN ID
* @param id
*/
setExtendedFlag(id: number): number;
/**
* Unsets the extended ID flag and returns the normal 29-bit CAN ID
* @param id
*/
unsetExtendedFlag(id: number): number;
protected bitGet(num: number, idx: number): string;
protected bitSet(num: number[], idx: number, val: number): number[];
protected bin2decSigned(bits: string): number;
protected bin2dec(bin: string): number;
protected dec2bin(dec: number, length: number): string;
/**
* Converts a signed decimal number to a binary string.
*
* @param dec number
* @param length number
* @returns string
*/
protected dec2binSigned(dec: number, length: number): string;
protected uint8ToBinary(dec: number): string;
/**
* Converts an uint8[] payload to a binary string
* @param payload number[] CAN payload in decimal.
* @param endian The type of encoding, Intel vs Motorola for the payload
*/
protected payload2Binary(payload: number[], endian: EndianType): string[];
/**
* Convert a binary string array into a byte array
*
* @param binaryArray string[]
* @returns number[]
*/
protected binary2Payload(binaryArray: string[], endian: EndianType): number[];
protected getStartOfBit(length: number, startBit: number, bitRange: number, endian: EndianType): number;
protected extractBitRange(binary: string[], startBit: number, bitRange: number, endian: EndianType): string[];
/**
* Inserts a bitField into a specific range within the binary string array.
*
* @param binary string[]
* @param bitField string
* @param startBit number
* @param bitRange number
* @param endian EndianType ('Motorola' or 'Intel')
* @returns string[]
*/
protected insertBitRange(binary: string[], bitField: string, startBit: number, bitRange: number, endian: EndianType): string[];
}
export default BitUtils;