Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3c00af7
Adding Github Action support.
jabrena Dec 5, 2020
4293c48
Fixing branch to run Github Actions
jabrena Dec 5, 2020
71574e2
Fixing typo message in Pipeline
jabrena Dec 5, 2020
900020f
Adding initial ideas to improve performance of Sysfs from @dwalend & …
jabrena Dec 5, 2020
9e005e2
drop FastIOUtil completely from JNA2
JakubVanek Dec 6, 2020
854e953
add lru-cached jna sysfs
JakubVanek Dec 6, 2020
2e503e5
tests: make tests compatible with new libc-based sysfs access
JakubVanek Dec 6, 2020
3ac9ffd
Upgrading README.md to add instructions to test in local.
jabrena Dec 6, 2020
6038607
Merge pull request #752 from JakubVanek/sysfs_perf_lru
jabrena Dec 6, 2020
76c0384
docs: add ILibc documentation
JakubVanek Dec 6, 2020
f943cbe
Uploading preliminar results with JMH
jabrena Dec 7, 2020
9920aa5
Merge pull request #753 from JakubVanek/sysfs_perf_doc
jabrena Dec 7, 2020
8a9a9cf
Changed the all-java optimization in Sysfs2.java to not be hard-coded…
dwalend Dec 7, 2020
31079af
Reading the short is definitely faster. Not sure about how to interpr…
dwalend Dec 9, 2020
3340b73
All Sysfs2.java unit tests pass for the minimal java read string opti…
dwalend Dec 9, 2020
57403cb
stray import removed
dwalend Dec 9, 2020
51c5c4e
There's potentially 27 bytes to read. Increasing buffer size to 32.
dwalend Dec 10, 2020
95505c8
Added the reusable DataChannelRereader and used it as filling for get…
dwalend Dec 11, 2020
5bc8f1b
Merge pull request #756 from dwalend/channelReset
jabrena Dec 13, 2020
f435da7
Removing files from previous alternatives.
jabrena Dec 23, 2020
d36cc72
Uploading JMH results
jabrena Dec 25, 2020
2ff973a
Cleaning the branch in order to merge in master
jabrena Dec 27, 2020
534588c
Cleaning the branch in order to merge in master
jabrena Dec 27, 2020
a10915d
Minor change to not import any class due to the description in Javadocs
jabrena Dec 27, 2020
19d18ee
Minor change to increase the readibility
jabrena Dec 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Java CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v1
with:
ref: master
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Gradle
run: ./gradlew test checkstyleMain
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
# ev3dev-lang-java

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

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](/LICENSE)
[![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)

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

# How to test?

For non Linux computers use:

```
./gradlew dockerTest
```

For Linux computers use:

```
./gradlew test
```

## Introduction

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

Lego Mindstorms ecosystem is `a nice educational way to learn Java programming in general and Robotics in particular`.
Now, it is possible to install a complete Linux distro in the third generation of the product and others companies like
Lego Mindstorms ecosystem is `a nice educational way to learn Java programming in general and Robotics in particular`.
Now, it is possible to install a complete Linux distro in the third generation of the product and others companies like
[Mindsensors](http://www.mindsensors.com/) & [Dexter Industries](https://www.dexterindustries.com/) has released products
which interact with Sensors & Actuators from Lego ecosystem and that boards can use the Power of the popular board
which interact with Sensors & Actuators from Lego ecosystem and that boards can use the Power of the popular board
[Raspberry Pi 3](https://www.raspberrypi.org/)
But, with the help of `EV3Dev`, it is possible to have the same Linux experience for multiple boards.
So... why not develop a Java library for that Linux Distro? The answer is `EV3Dev-lang-java`.
The project, takes the good things of both worlds: EV3Dev with the complete linux experience

But, with the help of `EV3Dev`, it is possible to have the same Linux experience for multiple boards.
So... why not develop a Java library for that Linux Distro? The answer is `EV3Dev-lang-java`.
The project, takes the good things of both worlds: EV3Dev with the complete linux experience
and LeJOS with the rich local navigation stack and the remote support in the future.

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

The library has support for `Debian Jessie` & `Debian Stretch`.
The library has support for `Debian Jessie` & `Debian Stretch`.
In this release, we have finished the support for `Debian Stretch` for EV3 and you could
use OpenJDK 11, or OpenJDK 14 and it is amazing!
use OpenJDK 11, or OpenJDK 15 and it is amazing!

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

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

**Note:** At the moment, we will maintain the whole solution until the next `LEGO Mindstorms` product estimated
for next January of 2021.
**Note:** At the moment, we will maintain the whole solution until the next `LEGO Mindstorms` product estimated
for next January of 2021.

## Features included in the whole project

**Java features**

* OpenJDK Java 11/12/13/14 support for EV3 Brick, Brickpi+/PiStorms + Raspberry Pi 3
* OpenJDK Java 11/12/13/14/15 support for EV3 Brick, Brickpi+/PiStorms + Raspberry Pi 3
* 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))
* Logging support based on [SLF4J](https://www.slf4j.org/)
* Centralized logs with [Kibana](https://www.elastic.co/products/kibana)
Expand All @@ -94,10 +108,10 @@ for next January of 2021.
* [RPLidar A1/A2](https://github.com/ev3dev-lang-java/usb-devices) (2D Lidar) Support

## Subprojects

Stable projects:
- [OpenJDK for EV3](https://github.com/ev3dev-lang-java/openjdk-ev3): A custom OpenJDK JRI/JDK (9,10,11,12) build for EV3

- [OpenJDK for EV3](https://github.com/ev3dev-lang-java/openjdk-ev3): A custom OpenJDK JRI/JDK (9,10,11,12) build for EV3
- [EV3Dev-lang-java](https://github.com/ev3dev-lang-java/ev3dev-lang-java): Low level integration with EV3Dev
- [lejos-commons](https://github.com/ev3dev-lang-java/lejos-commons): LeJOS interfaces & utilities
- [Installer](https://github.com/ev3dev-lang-java/installer): A set of Bash scripts to automate some operations with your brick
Expand Down Expand Up @@ -154,7 +168,7 @@ https://github.com/ev3dev-lang-java/examples
## References:

* LeJOS: http://www.lejos.org/
* LeJOS Git: http://sourceforge.net/p/lejos/ev3/code/ci/master/tree/
* LeJOS Git: http://sourceforge.net/p/lejos/ev3/code/ci/master/tree/
* LeJOS Forum: https://lejos.sourceforge.io/forum/search.php?keywords=ev3dev&sid=8642d9d1b361bcfdcdeabb26db89e632
* EV3Dev: http://www.ev3dev.org/
* EV3Dev // Getting Started: http://www.ev3dev.org/docs/getting-started/
Expand Down
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ dependencies {
api("net.java.dev.jna:jna:4.5.2")

testImplementation("ch.qos.logback:logback-classic:1.2.3")

testImplementation("commons-io:commons-io:2.5")

//TODO: Upgrade to JUnit 5
testImplementation("junit:junit:4.12")
//TODO: Review to add Mockito support
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("org.assertj:assertj-core:3.18.1")
}

compileJava.options.encoding = 'UTF-8'
Expand All @@ -68,7 +70,6 @@ tasks.withType(Checkstyle) {
ignoreFailures false
maxWarnings = 0
source 'src/main/java'
//exclude '**/ev3dev/sensors/'
reports {
xml.enabled false
html.enabled true
Expand Down Expand Up @@ -99,7 +100,7 @@ jacocoTestCoverageVerification {
rule {
limit {
//minimum = 0.75 // implement more tests
minimum = 0.3
minimum = 0.2
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/config.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
remotes {
ev3dev {
host = '192.168.1.151'
host = '192.168.1.157'
user = 'robot'
password = 'maker'
}
}
}
76 changes: 76 additions & 0 deletions src/main/java/ev3dev/utils/DataChannelRereader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ev3dev.utils;

import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Reader of streams that can reread the same channel for structured data of
* known length. The focus of this class is on performance.
*
* @author David Walend
*/
public class DataChannelRereader implements Closeable {

private final Path path;
private final ByteBuffer byteBuffer;
private final FileChannel channel;

/**
* Create a DataChannelRereader for path with a bufferLength byte buffer
*
* @param path path to the file to reread
* @param bufferLength length of the buffer to hold the structure
* @throws IOException when things go wrong
*/
public DataChannelRereader(Path path, int bufferLength) throws IOException {
this.path = path;
this.byteBuffer = ByteBuffer.allocate(bufferLength);
this.channel = FileChannel.open(path);
}

/**
* Create a DataChannelRereader for pathString with the default 32-byte buffer.
*
* @param pathString Path to the file to reread
* @throws IOException when things go wrong
*/
public DataChannelRereader(String pathString) throws IOException {
this(Paths.get(pathString),32);
}

/**
* @return a string made from the bytes in the file;
*/
public String readString() {
try {
int n;
do {
byteBuffer.clear();
channel.position(0);
n = channel.read(byteBuffer);
if (n == -1) {
throw new IOException("Premature end of file ");
}
} while (n <= 0);

byte[] bytes = byteBuffer.array();
if (bytes[n-1] == '\n') {
return new String(bytes, 0, n - 1, StandardCharsets.UTF_8);
} else {
return new String(bytes, 0, n, StandardCharsets.UTF_8);
}
} catch (IOException e) {
throw new RuntimeException("Problem reading path: " + path, e);
}
}

@Override
public void close() throws IOException {
channel.close();
}
}
46 changes: 25 additions & 21 deletions src/main/java/ev3dev/utils/Sysfs.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package ev3dev.utils;

import org.slf4j.Logger;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
* The class responsible to interact with Sysfs on EV3Dev
*
* @author Juan Antonio Breña Moral
* @author David Walend
*
*/
@Slf4j
public class Sysfs {

private static final Logger log = org.slf4j.LoggerFactory.getLogger(Sysfs.class);

/**
* Write a value in a file.
*
Expand All @@ -31,8 +30,8 @@ public class Sysfs {
* @return A boolean value if the operation was written or not.
*/
public static boolean writeString(final String filePath, final String value) {
if (log.isTraceEnabled()) {
log.trace("echo " + value + " > " + filePath);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("echo " + value + " > " + filePath);
}
try {
final File file = new File(filePath);
Expand All @@ -44,11 +43,11 @@ public static boolean writeString(final String filePath, final String value) {
out.close();
//TODO Review
} else {
log.error("File: '{}' without write permissions.", filePath);
LOGGER.error("File: '{}' without write permissions.", filePath);
return false;
}
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
LOGGER.error(e.getLocalizedMessage(), e);
return false;
}
return true;
Expand All @@ -65,21 +64,19 @@ public static boolean writeInteger(final String filePath, final int value) {
* @return value from attribute
*/
public static String readString(final String filePath) {
if (log.isTraceEnabled()) {
log.trace("cat " + filePath);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("cat " + filePath);
}
try {
final Path path = Paths.get(filePath);
if (existFile(path) && Files.isReadable(path)) {
final String result = Files.readAllLines(path, Charset.forName("UTF-8")).get(0);
if (log.isTraceEnabled()) {
log.trace("value: {}", result);
try (DataChannelRereader rereader = new DataChannelRereader(filePath)) {
String result = rereader.readString();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("value: {}", result);
}
return result;
}
throw new IOException("Problem reading path: " + filePath);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
LOGGER.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Problem reading path: " + filePath, e);
}
}
Expand All @@ -94,11 +91,19 @@ public static int readInteger(final String filePath) {
return Integer.parseInt(readString(filePath));
}

/**
* Read an Attribute in the Sysfs with containing Float values
*
* @param filePath path
* @return value from attribute
*/
public static float readFloat(final String filePath) {
return Float.parseFloat(readString(filePath));
}

/**
* Retrieve the elements contained in a path
*
* @param filePath path
* @return an List with options from a path
*/
Expand All @@ -118,8 +123,8 @@ public static List<File> getElements(final String filePath) {
* @return boolean
*/
public static boolean existPath(final String filePath) {
if (log.isTraceEnabled()) {
log.trace("ls " + filePath);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("ls " + filePath);
}
final File f = new File(filePath);
return f.exists() && f.isDirectory();
Expand All @@ -144,5 +149,4 @@ public static boolean writeBytes(final String path, final byte[] value) {
}
return true;
}

}
Loading