cabana: parse board units and comments
parent
144aaa981e
commit
b1e319cffd
|
@ -114,6 +114,22 @@ BO_ 228 STEERING_CONTROL: 5 ADAS
|
|||
|
||||
VAL_ 228 STEER_TORQUE_REQUEST 1 "requesting torque" 0 "not requesting torque" ;
|
||||
`;
|
||||
|
||||
const DBC_BOARD_UNITS = `
|
||||
BU_: first_board_unit second_board_unit
|
||||
`;
|
||||
|
||||
const DBC_BOARD_UNITS_WITH_COMMENT = `
|
||||
BU_: first_board_unit second_board_unit
|
||||
CM_ BU_ first_board_unit "first board unit comment";
|
||||
`;
|
||||
|
||||
const DBC_BOARD_UNITS_WITH_COMMENT_LINES = `
|
||||
BU_: first_board_unit second_board_unit
|
||||
CM_ BU_ first_board_unit "first board unit
|
||||
comment";
|
||||
`;
|
||||
|
||||
const steerTorqueSignal = new Signal({
|
||||
name: 'STEER_TORQUE',
|
||||
startBit: 7,
|
||||
|
@ -163,6 +179,22 @@ test('DBC parses multi-line message comment', () => {
|
|||
expect(msg.comment).toEqual("this message contains\nsteer torque information");
|
||||
});
|
||||
|
||||
test('DBC parses board unit names', () => {
|
||||
const dbcParsed = new DBC(DBC_BOARD_UNITS);
|
||||
expect(dbcParsed.boardUnits[0].name).toEqual("first_board_unit");
|
||||
expect(dbcParsed.boardUnits[1].name).toEqual("second_board_unit");
|
||||
});
|
||||
|
||||
test('DBC parses board unit comments', () => {
|
||||
const dbcParsed = new DBC(DBC_BOARD_UNITS_WITH_COMMENT);
|
||||
expect(dbcParsed.boardUnits[0].comment).toEqual("first board unit comment");
|
||||
});
|
||||
|
||||
test('DBC parses multi-line board unit comments', () => {
|
||||
const dbcParsed = new DBC(DBC_BOARD_UNITS_WITH_COMMENT_LINES);
|
||||
expect(dbcParsed.boardUnits[0].comment).toEqual("first board unit\ncomment");
|
||||
});
|
||||
|
||||
test('DBC parses signal value descriptions', () => {
|
||||
const dbcParsed = new DBC(DBC_SIGNALS_WITH_VAL);
|
||||
const {signals} = dbcParsed.messages.get(228);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
export default class BoardUnit {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.attributes = {};
|
||||
this.comment = null
|
||||
}
|
||||
|
||||
text() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import Bitarray from '../bitarray';
|
|||
|
||||
import Signal from './signal';
|
||||
import Frame from './frame';
|
||||
import BoardUnit from './BoardUnit';
|
||||
import DbcUtils from '../../utils/dbc';
|
||||
|
||||
const MSG_RE = /^BO\_ (\w+) (\w+) *: (\w+) (\w+)/
|
||||
|
@ -22,6 +23,10 @@ const SIGNAL_COMMENT_MULTI_LINE_RE = /^CM\_ SG\_ *(\w+) *(\w+) *\"(.*)/
|
|||
const MESSAGE_COMMENT_RE = /^CM\_ BO\_ *(\w+) *\"(.*)\";/;
|
||||
const MESSAGE_COMMENT_MULTI_LINE_RE = /^CM\_ BO\_ *(\w+) *\"(.*)/;
|
||||
|
||||
const BOARD_UNIT_RE = /^BU\_\:(.*)/;
|
||||
const BOARD_UNIT_COMMENT_RE = /^CM\_ BU\_ *(\w+) *\"(.*)\";/;
|
||||
const BOARD_UNIT_COMMENT_MULTI_LINE_RE = /^CM\_ BU\_ *(\w+) *\"(.*)/;
|
||||
|
||||
// Follow ups are used to parse multi-line comment definitions
|
||||
const FOLLOW_UP_SIGNAL_COMMENT = "FollowUpSignalComment";
|
||||
const FOLLOW_UP_MSG_COMMENT = "FollowUpMsgComment";
|
||||
|
@ -118,6 +123,7 @@ export default class DBC {
|
|||
|
||||
importDbcString(dbcString) {
|
||||
const messages = new Map();
|
||||
let boardUnits = [];
|
||||
let id = 0;
|
||||
let followUp = null;
|
||||
|
||||
|
@ -128,14 +134,16 @@ export default class DBC {
|
|||
|
||||
if(followUp != null) {
|
||||
const {type, data} = followUp;
|
||||
const followUpLine = `\n${line.substr(0, line.length - 2)}`;
|
||||
if(type === FOLLOW_UP_SIGNAL_COMMENT) {
|
||||
const signal = data;
|
||||
|
||||
signal.comment += `\n${line.substr(0, line.length - 2)}`;
|
||||
signal.comment += followUpLine;
|
||||
} else if(type === FOLLOW_UP_MSG_COMMENT) {
|
||||
const msg = data;
|
||||
|
||||
msg.comment += `\n${line.substr(0, line.length - 2)}`;
|
||||
msg.comment += followUpLine;
|
||||
} else if(type === FOLLOW_UP_BOARD_UNIT_COMMENT) {
|
||||
const boardUnit = data;
|
||||
boardUnit.comment += followUpLine;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,10 +221,10 @@ export default class DBC {
|
|||
}
|
||||
} else if(line.indexOf("CM_ SG_ ") === 0) {
|
||||
let matches = line.match(SIGNAL_COMMENT_RE);
|
||||
let isFollowUp = false;
|
||||
let hasFollowUp = false;
|
||||
if(matches === null) {
|
||||
matches = line.match(SIGNAL_COMMENT_MULTI_LINE_RE);
|
||||
isFollowUp = true;
|
||||
hasFollowUp = true;
|
||||
}
|
||||
if(matches === null) {
|
||||
console.warn('invalid signal comment', line);
|
||||
|
@ -235,15 +243,15 @@ export default class DBC {
|
|||
messages.set(messageId, msg);
|
||||
}
|
||||
|
||||
if(isFollowUp) {
|
||||
if(hasFollowUp) {
|
||||
followUp = {type: FOLLOW_UP_SIGNAL_COMMENT, data: signal}
|
||||
}
|
||||
} else if(line.indexOf("CM_ BO_ ") === 0) {
|
||||
let matches = line.match(MESSAGE_COMMENT_RE);
|
||||
let isFollowUp = false;
|
||||
let hasFollowUp = false;
|
||||
if(matches === null) {
|
||||
matches = line.match(MESSAGE_COMMENT_MULTI_LINE_RE);
|
||||
isFollowUp = true;
|
||||
hasFollowUp = true;
|
||||
if(matches === null) {
|
||||
console.warn('invalid message comment', line);
|
||||
return;
|
||||
|
@ -255,13 +263,46 @@ export default class DBC {
|
|||
const msg = messages.get(messageId);
|
||||
msg.comment = comment;
|
||||
|
||||
if(isFollowUp) {
|
||||
if(hasFollowUp) {
|
||||
followUp = {type: FOLLOW_UP_MSG_COMMENT, data: msg};
|
||||
}
|
||||
} else if(line.indexOf("BU_: ") === 0) {
|
||||
let matches = line.match(BOARD_UNIT_RE);
|
||||
|
||||
if(matches !== null) {
|
||||
const [boardUnitNameStr] = matches.slice(1);
|
||||
const newBoardUnits = boardUnitNameStr.split(' ')
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0)
|
||||
.map((name) => new BoardUnit(name));
|
||||
|
||||
boardUnits = boardUnits.concat(newBoardUnits);
|
||||
}
|
||||
} else if(line.indexOf("CM_ BU_ ") === 0) {
|
||||
let matches = line.match(BOARD_UNIT_COMMENT_RE);
|
||||
let hasFollowUp = false;
|
||||
if(matches === null) {
|
||||
matches = line.match(BOARD_UNIT_COMMENT_MULTI_LINE_RE)
|
||||
hasFollowUp = true;
|
||||
if(matches === null) {
|
||||
console.warn('invalid board unit comment', line);
|
||||
}
|
||||
}
|
||||
|
||||
let [boardUnitName, comment] = matches.slice(1);
|
||||
let boardUnit = boardUnits.find((bu) => bu.name == boardUnitName);
|
||||
if(boardUnit) {
|
||||
boardUnit.comment = comment;
|
||||
}
|
||||
|
||||
if(hasFollowUp) {
|
||||
followUp = {type: FOLLOW_UP_BOARD_UNIT_COMMENT, data: boardUnit};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.messages = messages;
|
||||
this.boardUnits = boardUnits;
|
||||
}
|
||||
|
||||
valueForInt64Signal(signalSpec, hexData) {
|
||||
|
|
Loading…
Reference in New Issue