File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
src/main/java/com/github/pires/obd/commands Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,12 @@ public ObdCommand(ObdCommand other) {
72
72
*/
73
73
public void run (InputStream in , OutputStream out ) throws IOException ,
74
74
InterruptedException {
75
- start = System .currentTimeMillis ();
76
- sendCommand (out );
77
- readResult (in );
78
- end = System .currentTimeMillis ();
75
+ synchronized (ObdCommand .class ) {//Only one command can write and read a data in one time.
76
+ start = System .currentTimeMillis ();
77
+ sendCommand (out );
78
+ readResult (in );
79
+ end = System .currentTimeMillis ();
80
+ }
79
81
}
80
82
81
83
/**
@@ -351,4 +353,19 @@ public final String getCommandPID() {
351
353
return cmd .substring (3 );
352
354
}
353
355
356
+ @ Override
357
+ public boolean equals (Object o ) {
358
+ if (this == o ) return true ;
359
+ if (o == null || getClass () != o .getClass ()) return false ;
360
+
361
+ ObdCommand that = (ObdCommand ) o ;
362
+
363
+ return cmd != null ? cmd .equals (that .cmd ) : that .cmd == null ;
364
+ }
365
+
366
+ @ Override
367
+ public int hashCode () {
368
+ return cmd != null ? cmd .hashCode () : 0 ;
369
+ }
370
+
354
371
}
You can’t perform that action at this time.
0 commit comments