Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18d4cb1

Browse files
authored
Merge pull request#761 from ev3dev-lang-java/sysfs_perf
Sysfs perf
2 parentsd8320a3 +19d18ee commit18d4cb1

File tree

9 files changed

+272
-55
lines changed

9 files changed

+272
-55
lines changed

‎.github/workflows/build.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name:Java CI
2+
on:[push]
3+
jobs:
4+
build:
5+
runs-on:ubuntu-latest
6+
steps:
7+
-name:Checkout source code
8+
uses:actions/checkout@v1
9+
with:
10+
ref:master
11+
-name:Set up JDK 11
12+
uses:actions/setup-java@v1
13+
with:
14+
java-version:11
15+
-name:Build with Gradle
16+
run:./gradlew test checkstyleMain

‎README.md‎

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
#ev3dev-lang-java
22

3-
*EV3Dev-lang-Java* is project to learn Java and create software for Mindstorms Robots using hardware supported by[EV3Dev](http://www.ev3dev.org/)
3+
*EV3Dev-lang-Java* is project to learn Java and create software for Mindstorms Robots using hardware supported by[EV3Dev](http://www.ev3dev.org/)
44
& the[LeJOS](http://www.lejos.org/) way.
55

66
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](/LICENSE)
77
[![Travis CI](https://travis-ci.org/ev3dev-lang-java/ev3dev-lang-java.svg?branch=develop)](https://travis-ci.org/ev3dev-lang-java/ev3dev-lang-java)
88

99
![ScreenShot](https://raw.githubusercontent.com/jabrena/ev3dev-lang-java/master/docs/images/theThreeAmigos.jpg)
1010

11+
#How to test?
12+
13+
For non Linux computers use:
14+
15+
```
16+
./gradlew dockerTest
17+
```
18+
19+
For Linux computers use:
20+
21+
```
22+
./gradlew test
23+
```
24+
1125
##Introduction
1226

13-
In Lego Mindstorms ecosystem, the default solution to develop Java software for Lego Mindstorms
14-
was[LeJOS](http://www.lejos.org/) but now exists one alternative,`EV3Dev-lang-java` a Java project
15-
running on the top of[EV3Dev](http://www.ev3dev.org/).
27+
In Lego Mindstorms ecosystem, the default solution to develop Java software for Lego Mindstorms
28+
was[LeJOS](http://www.lejos.org/) but now exists one alternative,`EV3Dev-lang-java` a Java project
29+
running on the top of[EV3Dev](http://www.ev3dev.org/).
1630

17-
Lego Mindstorms ecosystem is`a nice educational way to learn Java programming in general and Robotics in particular`.
18-
Now, it is possible to install a complete Linux distro in the third generation of the product and others companies like
31+
Lego Mindstorms ecosystem is`a nice educational way to learn Java programming in general and Robotics in particular`.
32+
Now, it is possible to install a complete Linux distro in the third generation of the product and others companies like
1933
[Mindsensors](http://www.mindsensors.com/) &[Dexter Industries](https://www.dexterindustries.com/) has released products
20-
which interact with Sensors & Actuators from Lego ecosystem and that boards can use the Power of the popular board
34+
which interact with Sensors & Actuators from Lego ecosystem and that boards can use the Power of the popular board
2135
[Raspberry Pi 3](https://www.raspberrypi.org/)
22-
23-
But, with the help of`EV3Dev`, it is possible to have the same Linux experience for multiple boards.
24-
So... why not develop a Java library for that Linux Distro? The answer is`EV3Dev-lang-java`.
25-
The project, takes the good things of both worlds: EV3Dev with the complete linux experience
36+
37+
But, with the help of`EV3Dev`, it is possible to have the same Linux experience for multiple boards.
38+
So... why not develop a Java library for that Linux Distro? The answer is`EV3Dev-lang-java`.
39+
The project, takes the good things of both worlds: EV3Dev with the complete linux experience
2640
and LeJOS with the rich local navigation stack and the remote support in the future.
2741

2842
**What Debian versions are supported with this library?**
2943

30-
The library has support for`Debian Jessie` &`Debian Stretch`.
44+
The library has support for`Debian Jessie` &`Debian Stretch`.
3145
In this release, we have finished the support for`Debian Stretch` for EV3 and you could
32-
use OpenJDK 11, or OpenJDK14 and it is amazing!
46+
use OpenJDK 11, or OpenJDK15 and it is amazing!
3347

34-
If you need to use any Raspberry Pi Boards, I recommend to use the stable`EV3Dev`
48+
If you need to use any Raspberry Pi Boards, I recommend to use the stable`EV3Dev`
3549
[Debian Jessie](http://www.ev3dev.org/downloads/) release.
3650

3751
**What is the hardware platforms supported in this project?**
@@ -57,18 +71,18 @@ The project has been designed with the following solution in mind:
5771
|---|------------------|--------------------------------------------|-------------------------|
5872
| 1| Platforms| BrickPi BrickPi3 PiStorms| EV3|
5973
| 2| OS| Debian Jessie| Debian Jessie/Stretch|
60-
| 3| JVM| OpenJDK14| OpenJDK JRI 11 / 12 / 13 / 14|
74+
| 3| JVM| OpenJDK15| OpenJDK JRI 11 / 12 / 13 / 14/ 15|
6175
| 4| EV3Dev Kernel| 4.4.47-19-ev3dev-rpi2| 4.14.71-ev3dev-2.3.0-ev3|
6276
| 5| ev3dev-lang-java| 0.7.0| 2.4.12|
6377

64-
**Note:** At the moment, we will maintain the whole solution until the next`LEGO Mindstorms` product estimated
65-
for next January of 2021.
78+
**Note:** At the moment, we will maintain the whole solution until the next`LEGO Mindstorms` product estimated
79+
for next January of 2021.
6680

6781
##Features included in the whole project
6882

6983
**Java features**
7084

71-
* OpenJDK Java 11/12/13/14 support for EV3 Brick, Brickpi+/PiStorms + Raspberry Pi 3
85+
* OpenJDK Java 11/12/13/14/15 support for EV3 Brick, Brickpi+/PiStorms + Raspberry Pi 3
7286
* Java profiling tools Support ([Oracle mission control](http://www.oracle.com/technetwork/java/javaseproducts/mission-control/java-mission-control-1998576.html) &[JConsole](http://docs.oracle.com/javase/7/docs/technotes/guides/management/jconsole.html))
7387
* Logging support based on[SLF4J](https://www.slf4j.org/)
7488
* Centralized logs with[Kibana](https://www.elastic.co/products/kibana)
@@ -94,10 +108,10 @@ for next January of 2021.
94108
*[RPLidar A1/A2](https://github.com/ev3dev-lang-java/usb-devices) (2D Lidar) Support
95109

96110
##Subprojects
97-
111+
98112
Stable projects:
99-
100-
-[OpenJDK for EV3](https://github.com/ev3dev-lang-java/openjdk-ev3): A custom OpenJDK JRI/JDK (9,10,11,12) build for EV3
113+
114+
-[OpenJDK for EV3](https://github.com/ev3dev-lang-java/openjdk-ev3): A custom OpenJDK JRI/JDK (9,10,11,12) build for EV3
101115
-[EV3Dev-lang-java](https://github.com/ev3dev-lang-java/ev3dev-lang-java): Low level integration with EV3Dev
102116
-[lejos-commons](https://github.com/ev3dev-lang-java/lejos-commons): LeJOS interfaces & utilities
103117
-[Installer](https://github.com/ev3dev-lang-java/installer): A set of Bash scripts to automate some operations with your brick
@@ -154,7 +168,7 @@ https://github.com/ev3dev-lang-java/examples
154168
##References:
155169

156170
* LeJOS:http://www.lejos.org/
157-
* LeJOS Git:http://sourceforge.net/p/lejos/ev3/code/ci/master/tree/
171+
* LeJOS Git:http://sourceforge.net/p/lejos/ev3/code/ci/master/tree/
158172
* LeJOS Forum:https://lejos.sourceforge.io/forum/search.php?keywords=ev3dev&sid=8642d9d1b361bcfdcdeabb26db89e632
159173
* EV3Dev:http://www.ev3dev.org/
160174
* EV3Dev // Getting Started:http://www.ev3dev.org/docs/getting-started/

‎build.gradle‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ dependencies {
4040
api("net.java.dev.jna:jna:4.5.2")
4141

4242
testImplementation("ch.qos.logback:logback-classic:1.2.3")
43-
4443
testImplementation("commons-io:commons-io:2.5")
4544

45+
//TODO: Upgrade to JUnit 5
4646
testImplementation("junit:junit:4.12")
47+
//TODO: Review to add Mockito support
4748
testImplementation("org.hamcrest:hamcrest-all:1.3")
49+
testImplementation("org.assertj:assertj-core:3.18.1")
4850
}
4951

5052
compileJava.options.encoding='UTF-8'
@@ -68,7 +70,6 @@ tasks.withType(Checkstyle) {
6870
ignoreFailuresfalse
6971
maxWarnings=0
7072
source'src/main/java'
71-
//exclude '**/ev3dev/sensors/'
7273
reports {
7374
xml.enabledfalse
7475
html.enabledtrue
@@ -99,7 +100,7 @@ jacocoTestCoverageVerification {
99100
rule {
100101
limit {
101102
//minimum = 0.75 // implement more tests
102-
minimum=0.3
103+
minimum=0.2
103104
}
104105
}
105106
}

‎gradle/config.gradle‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
remotes {
22
ev3dev {
3-
host='192.168.1.151'
3+
host='192.168.1.157'
44
user='robot'
55
password='maker'
66
}
7-
}
7+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
packageev3dev.utils;
2+
3+
importjava.io.Closeable;
4+
importjava.io.IOException;
5+
importjava.nio.ByteBuffer;
6+
importjava.nio.channels.FileChannel;
7+
importjava.nio.charset.StandardCharsets;
8+
importjava.nio.file.Path;
9+
importjava.nio.file.Paths;
10+
11+
/**
12+
* Reader of streams that can reread the same channel for structured data of
13+
* known length. The focus of this class is on performance.
14+
*
15+
* @author David Walend
16+
*/
17+
publicclassDataChannelRereaderimplementsCloseable {
18+
19+
privatefinalPathpath;
20+
privatefinalByteBufferbyteBuffer;
21+
privatefinalFileChannelchannel;
22+
23+
/**
24+
* Create a DataChannelRereader for path with a bufferLength byte buffer
25+
*
26+
* @param path path to the file to reread
27+
* @param bufferLength length of the buffer to hold the structure
28+
* @throws IOException when things go wrong
29+
*/
30+
publicDataChannelRereader(Pathpath,intbufferLength)throwsIOException {
31+
this.path =path;
32+
this.byteBuffer =ByteBuffer.allocate(bufferLength);
33+
this.channel =FileChannel.open(path);
34+
}
35+
36+
/**
37+
* Create a DataChannelRereader for pathString with the default 32-byte buffer.
38+
*
39+
* @param pathString Path to the file to reread
40+
* @throws IOException when things go wrong
41+
*/
42+
publicDataChannelRereader(StringpathString)throwsIOException {
43+
this(Paths.get(pathString),32);
44+
}
45+
46+
/**
47+
* @return a string made from the bytes in the file;
48+
*/
49+
publicStringreadString() {
50+
try {
51+
intn;
52+
do {
53+
byteBuffer.clear();
54+
channel.position(0);
55+
n =channel.read(byteBuffer);
56+
if (n == -1) {
57+
thrownewIOException("Premature end of file ");
58+
}
59+
}while (n <=0);
60+
61+
byte[]bytes =byteBuffer.array();
62+
if (bytes[n-1] =='\n') {
63+
returnnewString(bytes,0,n -1,StandardCharsets.UTF_8);
64+
}else {
65+
returnnewString(bytes,0,n,StandardCharsets.UTF_8);
66+
}
67+
}catch (IOExceptione) {
68+
thrownewRuntimeException("Problem reading path: " +path,e);
69+
}
70+
}
71+
72+
@Override
73+
publicvoidclose()throwsIOException {
74+
channel.close();
75+
}
76+
}

‎src/main/java/ev3dev/utils/Sysfs.java‎

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
packageev3dev.utils;
22

3-
importorg.slf4j.Logger;
4-
53
importjava.io.File;
64
importjava.io.IOException;
75
importjava.io.PrintWriter;
8-
importjava.nio.charset.Charset;
96
importjava.nio.file.Files;
107
importjava.nio.file.Path;
118
importjava.nio.file.Paths;
129
importjava.nio.file.StandardOpenOption;
1310
importjava.util.ArrayList;
1411
importjava.util.Arrays;
1512
importjava.util.List;
13+
importlombok.extern.slf4j.Slf4j;
1614

1715
/**
1816
* The class responsible to interact with Sysfs on EV3Dev
1917
*
2018
* @author Juan Antonio Breña Moral
19+
* @author David Walend
20+
*
2121
*/
22+
@Slf4j
2223
publicclassSysfs {
2324

24-
privatestaticfinalLoggerlog =org.slf4j.LoggerFactory.getLogger(Sysfs.class);
25-
2625
/**
2726
* Write a value in a file.
2827
*
@@ -31,8 +30,8 @@ public class Sysfs {
3130
* @return A boolean value if the operation was written or not.
3231
*/
3332
publicstaticbooleanwriteString(finalStringfilePath,finalStringvalue) {
34-
if (log.isTraceEnabled()) {
35-
log.trace("echo " +value +" > " +filePath);
33+
if (LOGGER.isTraceEnabled()) {
34+
LOGGER.trace("echo " +value +" > " +filePath);
3635
}
3736
try {
3837
finalFilefile =newFile(filePath);
@@ -44,11 +43,11 @@ public static boolean writeString(final String filePath, final String value) {
4443
out.close();
4544
//TODO Review
4645
}else {
47-
log.error("File: '{}' without write permissions.",filePath);
46+
LOGGER.error("File: '{}' without write permissions.",filePath);
4847
returnfalse;
4948
}
5049
}catch (IOExceptione) {
51-
log.error(e.getLocalizedMessage(),e);
50+
LOGGER.error(e.getLocalizedMessage(),e);
5251
returnfalse;
5352
}
5453
returntrue;
@@ -65,21 +64,19 @@ public static boolean writeInteger(final String filePath, final int value) {
6564
* @return value from attribute
6665
*/
6766
publicstaticStringreadString(finalStringfilePath) {
68-
if (log.isTraceEnabled()) {
69-
log.trace("cat " +filePath);
67+
if (LOGGER.isTraceEnabled()) {
68+
LOGGER.trace("cat " +filePath);
7069
}
7170
try {
72-
finalPathpath =Paths.get(filePath);
73-
if (existFile(path) &&Files.isReadable(path)) {
74-
finalStringresult =Files.readAllLines(path,Charset.forName("UTF-8")).get(0);
75-
if (log.isTraceEnabled()) {
76-
log.trace("value: {}",result);
71+
try (DataChannelRereaderrereader =newDataChannelRereader(filePath)) {
72+
Stringresult =rereader.readString();
73+
if (LOGGER.isTraceEnabled()) {
74+
LOGGER.trace("value: {}",result);
7775
}
7876
returnresult;
7977
}
80-
thrownewIOException("Problem reading path: " +filePath);
8178
}catch (IOExceptione) {
82-
log.error(e.getLocalizedMessage(),e);
79+
LOGGER.error(e.getLocalizedMessage(),e);
8380
thrownewRuntimeException("Problem reading path: " +filePath,e);
8481
}
8582
}
@@ -94,11 +91,19 @@ public static int readInteger(final String filePath) {
9491
returnInteger.parseInt(readString(filePath));
9592
}
9693

94+
/**
95+
* Read an Attribute in the Sysfs with containing Float values
96+
*
97+
* @param filePath path
98+
* @return value from attribute
99+
*/
97100
publicstaticfloatreadFloat(finalStringfilePath) {
98101
returnFloat.parseFloat(readString(filePath));
99102
}
100103

101104
/**
105+
* Retrieve the elements contained in a path
106+
*
102107
* @param filePath path
103108
* @return an List with options from a path
104109
*/
@@ -118,8 +123,8 @@ public static List<File> getElements(final String filePath) {
118123
* @return boolean
119124
*/
120125
publicstaticbooleanexistPath(finalStringfilePath) {
121-
if (log.isTraceEnabled()) {
122-
log.trace("ls " +filePath);
126+
if (LOGGER.isTraceEnabled()) {
127+
LOGGER.trace("ls " +filePath);
123128
}
124129
finalFilef =newFile(filePath);
125130
returnf.exists() &&f.isDirectory();
@@ -144,5 +149,4 @@ public static boolean writeBytes(final String path, final byte[] value) {
144149
}
145150
returntrue;
146151
}
147-
148152
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp