Skip to content

Commit 12df485

Browse files
author
julietkilo
committed
message interval feature implemented
1 parent 58c826e commit 12df485

File tree

2 files changed

+73
-35
lines changed

2 files changed

+73
-35
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- THE BASICS -->
99
<groupId>com.github.canbabel</groupId>
1010
<artifactId>CANBabel</artifactId>
11-
<version>1.0-SNAPSHOT</version>
11+
<version>1.1-SNAPSHOT</version>
1212
<packaging>jar</packaging>
1313
<dependencies>
1414
<dependency>

src/main/java/com/github/canbabel/canio/dbc/DbcReader.java

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public class DbcReader {
9090
private ObjectFactory factory = null;
9191
private NetworkDefinition network = null;
9292
private Document document = null;
93-
private Bus bus = null;
93+
private static Bus bus = null;
9494
private Map<Long, Set<Signal>> muxed = new TreeMap<Long, Set<Signal>>();
9595
private Set<LabelDescription> labels = new HashSet<LabelDescription>();
9696
private Set<SignalComment> signalComments = new HashSet<SignalComment>();
9797
private String version = "";
98-
private PrintWriter logWriter;
99-
98+
private static PrintWriter logWriter;
99+
100100
private static class LabelDescription {
101101

102102
private long id;
@@ -177,33 +177,67 @@ public void setSignalName(String signalName) {
177177
}
178178
};
179179

180-
private static Signal findSignal(List<Message> messages, long id, boolean e, String name) {
181-
for (Message message : messages) {
180+
/**
181+
* Find a single CAN message from the list of messages
182+
* @param messages List of message objects
183+
* @param id CAN identifier of the message to find
184+
* @param e True, if the message to find is of extended frame format
185+
* @return Message object found, null otherwise
186+
*/
187+
private static Message findMessage(List<Message> messages, long id, boolean e) {
188+
for (Message message : messages){
182189
boolean extended = "extended".equals(message.getFormat());
183190
if (Long.parseLong(message.getId().substring(2), 16) == id
184191
&& extended == e) {
185-
List<Signal> signals = message.getSignal();
186-
/* Find signal name */
187-
for (Signal signal : signals) {
192+
return message;
193+
}
194+
}
195+
return null;
196+
}
197+
198+
/**
199+
* Find a single CAN signal from list of CAN messages.
200+
* @param messages List of messages object
201+
* @param id Identifier of CAN message to find
202+
* @param e True, if CAN message to find is extended frame format
203+
* @param name Name of signal to find
204+
* @return Signal object found, null otherwise
205+
*/
206+
private static Signal findSignal(List<Message> messages, long id, boolean e, String name) {
207+
Message message;
208+
message = findMessage(messages, id, e);
209+
List<Signal> signals;
210+
211+
if (message != null){
212+
signals = message.getSignal();
213+
} else if (id == 0) {
214+
/* orphaned signal found */
215+
return null;
216+
} else {
217+
/* valid signal found but message not defined */
218+
return null;
219+
}
220+
221+
222+
/* Find signal name */
223+
for (Signal signal : signals) {
224+
if (signal.getName().equals(name)) {
225+
return signal;
226+
}
227+
}
228+
229+
for (Multiplex multiplex : message.getMultiplex()) {
230+
for (MuxGroup group : multiplex.getMuxGroup()) {
231+
for (Signal signal : group.getSignal()) {
188232
if (signal.getName().equals(name)) {
189233
return signal;
190234
}
191235
}
192-
193-
for (Multiplex multiplex : message.getMultiplex()) {
194-
for (MuxGroup group : multiplex.getMuxGroup()) {
195-
for (Signal signal : group.getSignal()) {
196-
if (signal.getName().equals(name)) {
197-
return signal;
198-
}
199-
}
200-
}
201-
}
202236
}
203-
}
237+
}
204238
return null;
205239
}
206-
240+
207241

208242
/**
209243
* Read in given CAN database file (*.dbc)
@@ -280,7 +314,9 @@ public boolean parseFile(File file, OutputStream logStream) {
280314
List<BasicLabelType> labellist = set.getLabelOrLabelGroup();
281315
labellist.addAll(description.getLabels());
282316

283-
Signal signal = findSignal(messages, description.getId(), description.isExtended(), description.getSignalName());
317+
Signal signal = null;
318+
signal = findSignal(messages, description.getId(), description.isExtended(), description.getSignalName());
319+
284320
if (signal != null) {
285321
signal.setLabelSet(set);
286322
}
@@ -299,7 +335,7 @@ public boolean parseFile(File file, OutputStream logStream) {
299335
signal.setNotes(comment.getComment());
300336
}
301337
}
302-
338+
303339
return true;
304340
}
305341

@@ -483,17 +519,20 @@ private static void parseComment(StringBuffer line) {
483519
*/
484520
private static void parseAttribute(StringBuffer line) {
485521

486-
// if (Pattern.matches("BA_\\s+\"GenMsgCycleTime.*", line)) {
487-
// String[] splitted = splitString(line.toString());
488-
// if (splitted != null) {
489-
// //System.out.println("Attribute: " + line.toString());
490-
//
491-
// System.out.println("id: "+splitted[3]+"cycle: "+splitted[4].substring(0, splitted[4].length()-1));
492-
// }
493-
// }
522+
List<Message> messages = bus.getMessage();
494523

495-
// TODO getMessageByCanId needed to attach cycle time to a message node
496-
// messag context : List<Message> messages = bus.getMessage();
524+
/* Find message with given id in GenMsgCycleTime and attach to message node */
525+
if (Pattern.matches("BA_\\s+\"GenMsgCycleTime.*", line)) {
526+
String[] splitted = splitString(line.toString());
527+
if (splitted != null) {
528+
Message message = findMessage(messages, Long.valueOf(splitted[3]), isExtendedFrameFormat(splitted[3]) );
529+
Integer ival = Integer.valueOf(splitted[4].substring(0, splitted[4].length()-1));
530+
// Omit default interval = 0
531+
if (ival != 0) {
532+
message.setInterval(ival);
533+
}
534+
}
535+
}
497536
}
498537

499538
/**
@@ -508,7 +547,6 @@ private void parseMessageDefinition(StringBuffer line) {
508547
muxed = new TreeMap<Long, Set<Signal>>();
509548

510549
// BO_ 1984 Messagename: 8 Producername
511-
// System.out.println("Message Definition: " + line.toString());
512550

513551
// remove BO_
514552
line.replace(0, 4, "");
@@ -591,7 +629,7 @@ private int getCanIdFromString(String canIdStr) {
591629
return canId;
592630
}
593631

594-
private boolean isExtendedFrameFormat(String canIdStr) {
632+
private static boolean isExtendedFrameFormat(String canIdStr) {
595633

596634
long canIdLong = Long.valueOf(canIdStr).longValue();
597635
return ((canIdLong >>> 31 & 1) == 1) ? true : false;

0 commit comments

Comments
 (0)