Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
**/xtend-gen/
**/*.java._trace
**/*.xtendbin
!/src/main/vql-gen/*
51 changes: 38 additions & 13 deletions src/java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
//Gradle plugins
plugins {
id "org.xtext.xtend" version "1.0.12" apply false
id "org.xtext.xtend" version "2.0.1" apply false
id "com.google.protobuf" version "0.8.3" apply false

// id "org.sonarqube" version "2.5"
id 'org.hidetake.ssh' version '2.7.0'
id 'com.diffplug.gradle.p2.asmaven' version '3.0.6'

id 'com.github.johnrengelman.shadow' version '2.0.1'
}

ssh.settings { knownHosts = allowAnyHosts }

//sonarqube {
// properties { property "sonar.projectName", "MoDeS3" }
//}

subprojects {
ext{
viatraVersion = '1.7.0'
xtendVersion = '2.9.0'
xtendVersion = '2.11.0'
componentsPrefix = gradle.ext.componentsPrefix
safetylogicPrefix = gradle.ext.safetylogicPrefix
messagingPrefix = gradle.ext.messagingPrefix
Expand All @@ -37,23 +35,50 @@ subprojects {
}

plugins.withType(JavaPlugin) {

sourceCompatibility = 1.8
targetCompatibility = 1.8


test {
useJUnitPlatform()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.slf4j:slf4j-simple:1.7.21'
//compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.9.0'

compile group: 'org.eclipse.xtend', name: 'org.eclipse.xtend.lib', version: xtendVersion

testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.10.19"
}
def mockitoVersion = '2.23.0'
def powermockVersion = '2.0.0-beta.5'

testCompile("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
testCompile("org.mockito:mockito-core:${mockitoVersion}")
testCompile("org.powermock:powermock-core:${powermockVersion}")
testCompile("org.powermock:powermock-api-mockito2:${powermockVersion}")
testCompile("org.powermock:powermock-module-junit4:${powermockVersion}")

def junit4Version = '4.12'
def junitVintageVersion = '5.3.1'
def junitJupiterVersion = '5.3.1'
def junitPlatformVersion = '1.3.1'
// JUnit Jupiter API and TestEngine implementation
testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")

testCompile("org.junit.jupiter:junit-jupiter-params:${junitJupiterVersion}"){
because 'allows Parameterized notation for JUnit 4 tests'
}
testCompile("junit:junit:${junit4Version}")
testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}

testRuntime("org.junit.platform:junit-platform-launcher:${junitPlatformVersion}") {
because 'allows tests to run from IDEs that bundle older version of launcher'
}
}
}



plugins.withType(org.xtext.gradle.XtendLanguagePlugin) {
sourceSets {
main {
Expand Down
16 changes: 13 additions & 3 deletions src/java/components/barrier/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/xtend-gen"/>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/xtend-gen">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 19 additions & 4 deletions src/java/components/dashboard/.classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/webapp">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
22 changes: 19 additions & 3 deletions src/java/components/gpiomanager/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
*/
package hu.bme.mit.inf.modes3.components.gpiomanager;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -21,7 +17,7 @@
*
* @author zsoltmazlo
*/
public final class Gpio {
public class Gpio {

public enum Level {
LOW, HIGH
Expand Down Expand Up @@ -57,34 +53,42 @@ public interface InputStateListener {

private TimerTask _inputListenerTask;

public Gpio(int pin, Direction direction) throws IOException, GpioNotConfiguratedException {
private ICommandWriter _writer;

private ICommandReader _reader;

public Gpio(int pin, Direction direction, ICommandWriter writer, ICommandReader reader) throws IOException {
this._pin = pin;
this._direction = direction;
this._reader = reader;
this._writer = writer;
this._gpioFolder = GPIO_BASE_FOLDER + "gpio" + this._pin + "/";
}

public void initializeGpio() throws IOException {
// export gpio pin first
try {
executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "export");
_writer.executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "export");
} catch (Exception ex) {
Logger.error(TAG, "Pin export failed! Pin: %d", _pin);

Logger.error(TAG, "Pin export failed! Pin: %d" + "\n" + ex.getCause(), _pin);

// if GPIO pin exporting failed, the cause of the failure is the
// fact that the GPIO has already exported previously
// in this case, we should unexport it and try to export it again
// if unexport fails also, there should be something wrong
try {
executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "unexport");
executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "export");
_writer.executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "unexport");
_writer.executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "export");
} catch (Exception ex2) {
Logger.error(TAG, "Pin re-export failed! Pin: %d", _pin);
throw ex2;
}
}

this._gpioFolder = GPIO_BASE_FOLDER + "gpio" + this._pin + "/";

// set direction of pin
try {
executeCommand(this._direction.toString().toLowerCase(), _gpioFolder + "direction");
_writer.executeCommand(this._direction.toString().toLowerCase(), _gpioFolder + "direction");
} catch (Exception ex) {
Logger.error(TAG, "Pin direction setup failed! Pin: %d", _pin);
throw ex;
Expand All @@ -93,7 +97,7 @@ public Gpio(int pin, Direction direction) throws IOException, GpioNotConfigurate
switch (this._direction) {
case IN:
// setup edge detection as well
executeCommand("both", _gpioFolder + "edge");
_writer.executeCommand("both", _gpioFolder + "edge");

setupInputChangeListening();
break;
Expand All @@ -102,12 +106,11 @@ public Gpio(int pin, Direction direction) throws IOException, GpioNotConfigurate
this.setLevel(Level.LOW);
break;
}

}

public final void setLevel(Level level) throws IOException {
try {
executeCommand(level == Level.HIGH ? "1" : "0", _gpioFolder + "value");
_writer.executeCommand(level == Level.HIGH ? "1" : "0", _gpioFolder + "value");
this._level = level;
} catch (IOException ex) {
Logger.error(TAG, "Level setting failed! Pin: %d", _pin);
Expand Down Expand Up @@ -155,46 +158,33 @@ public final void removeInputStateListener(InputStateListener listener) {
this.listeners.remove(listener);
}

private void executeCommand(String value, String targetFile) throws IOException {
Logger.info(TAG, "Trying to write \"%s\" to %s", value, targetFile);
try (BufferedWriter w = new BufferedWriter(new FileWriter(targetFile))) {
w.append(value);
w.newLine();
w.flush();
}
Logger.info(TAG, "Succeeded!");
}

private class InputStateChangeListenerTask extends TimerTask {

@Override
public void run() {
try {
try (BufferedReader reader = new BufferedReader(new FileReader(_gpioFolder + "value"))) {
Level newLevel = reader.readLine().equals("1") ? Level.HIGH : Level.LOW;
if (!newLevel.equals(_level)) {
Logger.info(TAG, "Pin state changed! Pin: %d Value: %s", _pin, newLevel.toString());
_level = newLevel;
listeners.stream().forEach((listener) -> {
try {
listener.levelStateChanged(_level);
} catch (Exception ex) {
Logger.error(TAG, "Error while notifying the InputStateChangeListener (%s)",
listener.toString());
Logger.error(TAG, ex.getMessage());
}
});
}
Level newLvl = _reader.getGpioValue(_gpioFolder + "value");
if (newLvl != null && !newLvl.equals(_level)) {
Logger.info(TAG, "Pin state changed! Pin: %d Value: %s", _pin, newLvl.toString());
_level = newLvl;
listeners.stream().forEach((listener) -> {
try {
listener.levelStateChanged(_level);
} catch (Exception ex) {
Logger.error(TAG, "Error while notifying the InputStateChangeListener (%s)", listener.toString());
Logger.error(TAG, ex.getMessage());
}
});
}

} catch (FileNotFoundException ex) {
Logger.error(TAG, "InputStateChangeListenerTask is aborted, because pin #%d's value file not found!",
_pin);
Logger.error(TAG, "InputStateChangeListenerTask is aborted, because pin #%d's value file not found!", _pin);
Logger.error(TAG, ex.getMessage());
} catch (IOException ex) {
Logger.error(TAG, "InputStateChangeListenerTask is aborted, IO error during file read on pin #%d",
_pin);
Logger.error(TAG, "InputStateChangeListenerTask is aborted, IO error during file read on pin #%d", _pin);
Logger.error(TAG, ex.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
Logger.error(TAG, "Something is wrong here: " + ex.getMessage());
}
}

Expand All @@ -209,7 +199,7 @@ private void setupInputChangeListening() throws IOException {
}
}

public final void cleanup() throws IOException, InterruptedException {
public final void cleanup() throws IOException {
// unexport gpio pin
try {
if (_isInputListenerRunning) {
Expand All @@ -220,7 +210,7 @@ public final void cleanup() throws IOException, InterruptedException {
_isInputListenerRunning = false;
Logger.info(TAG, "Listening service for pin #%d stopped.", _pin);
}
executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "unexport");
_writer.executeCommand(String.valueOf(_pin), GPIO_BASE_FOLDER + "unexport");
} catch (IOException ex) {
Logger.error(TAG, "Pin unexport failed! Pin: %d", _pin);
throw ex;
Expand Down
Loading