Skip to content

Commit

Permalink
Merge branch 'release/2018.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sfeilmeier committed Mar 29, 2018
2 parents 1dbd2e4 + cafd861 commit c7fa2eb
Show file tree
Hide file tree
Showing 159 changed files with 11,127 additions and 12,783 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,28 @@ The target of this short guide is to quickly setup a development environment on
### Setup OpenEMS simulator

1. Download [Eclipse for Java](https://www.eclipse.org/), install and start it
2. Import both the "Edge" and the "Common" project in Eclipse:
2. Install [BndTools](http://bndtools.org/) in Eclipse:

Menu: `File` → `Import...` → `General` → `Existing Projects into Workspace` →
Select root directory: `Browse...` → Select the "edge" and "common" directories → `OK` → `Finish`

3. Apply the simulator template configuration.
Menu: `Help` → `Eclipse Marketplace...` → `Find:` → enter `BndTools` → press `Install`

3. Import OSGi projects:

Menu: `File` → `Import...` → `Bndtools` → `Existing Bnd Workspace` → Root directory: `Browse...` → select the directory with the source code → `OK` → `Finish` → "Switch to Bndtools perspective?" `yes`

If Eclipse shows errors: Because of a bug in Bndtools it is necessary to manually trigger a build. Doubleclick the `cnf` project → doubleclick `build.bnd` → click on `Reload` in bottom right of the window. The errors should all disappear.

4. Import Java projects:

Menu: `File``Import...``General``Existing Projects into Workspace` → "Select root directory:" `Browse...` → select the directory with the source code → `Finish`

5. Apply the simulator template configuration.
Hint: OpenEMS is using a global JSON configuration file.

Copy `template/Simulator.json` to `etc/openems.d/config.json`

Open the `openems` project and copy `template/Simulator.json` to `etc/openems.d/config.json`

4. Right click on `src/io.openems/App.java` and select `Run As...``Java Application`.
6. Right click on `src/io.openems/App.java` and select `Run As...``Java Application`.

5. You should see it running in the console.
7. You should see it running in the console.

### Setup OpenEMS UI

Expand Down Expand Up @@ -141,7 +149,7 @@ The file is split into three sections:
In the things section you need to set all devices to communicate with.
Therefore you have to use a so called "Bridge". A Bridge connects several devices(Hardware) with the same protocol to openems. For example you want to read the data of a Socomec Meter and FeneconPro which are connected to the same RS485 Bus, you have to use a ModbusRtu bridge and set the Socomec Meter and FeneconPro as devices for this bridge. Each bridge/device has ConfigChannels to provide the paremters to establish the connection. The required parameters can be found in the according class. A device has DeviceNatures, where each nature requires a unique id. This id is used as reference by the controllers.
2. `scheduler`: The Scheduler executes the controllers according to the programmed behaviour. For example the SimpleScheduler orders and executes the Controller by the configured priority. Controllers are the smallest divisible logical control unit. Each Controller needs at least one device reference to do the work.
3. `persistance`:
3. `persistence`:

Example configuration:
```
Expand Down
1 change: 0 additions & 1 deletion common/.gitignore

This file was deleted.

23 changes: 0 additions & 23 deletions common/.project

This file was deleted.

2 changes: 1 addition & 1 deletion edge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<url>http://openems.io</url>
<groupId>io.openems</groupId>
<artifactId>edge</artifactId>
<version>2018.3.1</version>
<version>2018.4.0</version>
<packaging>jar</packaging>
<scm>
<url>https://github.com/OpenEMS/openems</url>
Expand Down
2 changes: 1 addition & 1 deletion edge/src/io/openems/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.openems.core.Config;

public class App {
private static Logger log = LoggerFactory.getLogger(App.class);
private final static Logger log = LoggerFactory.getLogger(App.class);

public static void main(String[] args) {
log.info("OpenEMS started");
Expand Down
5 changes: 3 additions & 2 deletions edge/src/io/openems/api/bridge/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
import io.openems.core.utilities.Mutex;

public abstract class Bridge extends Thread implements Thing {

public final static String THINGID_PREFIX = "_bridge";
private final Logger log = LoggerFactory.getLogger(Bridge.class);

private static int instanceCounter = 0;
private Scheduler scheduler;
private int readOtherTaskIndex = 0;
Expand All @@ -54,7 +57,6 @@ public abstract class Bridge extends Thread implements Thing {
private Mutex initializedMutex = new Mutex(false);
private final AtomicBoolean isInitialized = new AtomicBoolean(false);
protected final List<Device> devices = Collections.synchronizedList(new LinkedList<Device>());
protected final Logger log;
private DebugChannel<Long> requiredCycleTime = new DebugChannel<>("RequiredCycleTime", this);
private Map<BridgeEventListener, Long> eventListener = new HashMap<>();
private DebugChannel<Integer> readOtherTaskReadCount = new DebugChannel<>("ReadOtherTaskReadCount", this);
Expand All @@ -66,7 +68,6 @@ public abstract class Bridge extends Thread implements Thing {
* @param name
*/
public Bridge() {
log = LoggerFactory.getLogger(this.getClass());
setName(THINGID_PREFIX + instanceCounter++);
thingState = new ThingStateChannels(this);
}
Expand Down
8 changes: 8 additions & 0 deletions edge/src/io/openems/api/channel/FunctionalReadChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public FunctionalReadChannel<T> unit(String unit) {
super.unit(unit);
return this;
}

@Override
public ReadChannel<T> required() {
this.channels.forEach(channel -> {
channel.required();
});
return super.required();
}
}
4 changes: 2 additions & 2 deletions edge/src/io/openems/api/channel/ReadChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
import io.openems.core.utilities.InjectionUtils;

public class ReadChannel<T> implements Channel, Comparable<ReadChannel<T>> {
protected final Logger log;

private final Logger log = LoggerFactory.getLogger(ReadChannel.class);

private final String id;
private final Thing parent;
Expand All @@ -68,7 +69,6 @@ public class ReadChannel<T> implements Channel, Comparable<ReadChannel<T>> {
private final Set<ChannelChangeListener> changeListeners = ConcurrentHashMap.newKeySet();

public ReadChannel(String id, Thing parent) {
log = LoggerFactory.getLogger(this.getClass());
this.id = id;
this.parent = parent;
}
Expand Down
5 changes: 4 additions & 1 deletion edge/src/io/openems/api/channel/WriteChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Map.Entry;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.JsonElement;

import io.openems.api.controller.Controller;
Expand All @@ -34,9 +37,9 @@
import io.openems.common.session.Role;
import io.openems.common.utils.JsonUtils;


public class WriteChannel<T> extends ReadChannel<T> {

private final Logger log = LoggerFactory.getLogger(WriteChannel.class);
private final Interval<ReadChannel<T>> writeChannelInterval = new Interval<ReadChannel<T>>();
private final Interval<T> writeInterval = new Interval<T>();
private Optional<T> writeValue = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.Optional;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.api.channel.Channel;
import io.openems.api.channel.ChannelChangeListener;
import io.openems.api.channel.ReadChannel;
Expand All @@ -21,6 +24,7 @@

public class ThingStateChannels extends ReadChannel<ThingState> implements ChannelChangeListener {

private final Logger log = LoggerFactory.getLogger(ThingStateChannels.class);
private List<ThingStateChannel> warningChannels;
private List<ThingStateChannel> faultChannels;
private Set<ChannelAddress> channelNames;
Expand Down Expand Up @@ -118,6 +122,11 @@ public boolean isArray() {
public String defaultValue() {
return "";
}

@Override
public String jsonSchema() {
return "";
}
}));
try {
channel.setChannelDoc(channelDoc);
Expand Down
7 changes: 4 additions & 3 deletions edge/src/io/openems/api/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import io.openems.api.thing.Thing;

public abstract class Controller implements Thing {

public final static String THINGID_PREFIX = "_controller";
private final Logger log = LoggerFactory.getLogger(Controller.class);

private static int instanceCounter = 0;
protected final Logger log;
private String name;
private DebugChannel<Long> requiredTime = new DebugChannel<>("RequiredTime", this);

Expand All @@ -55,7 +57,6 @@ public Controller(String thingId) {
if (thingId == null) {
thingId = THINGID_PREFIX + instanceCounter++;
}
log = LoggerFactory.getLogger(this.getClass());
name = thingId;
}

Expand All @@ -66,7 +67,7 @@ public void executeRun() {
try {
run();
} catch (Throwable e) {
log.error("execution of Controller ["+id()+"] failed. "+e.getMessage());
log.error("execution of Controller ["+id()+"] with Implementation ["+this.getClass().getSimpleName()+"] failed. " + e.getClass().getSimpleName() + ": " +e.getMessage());
}
requiredTime.setValue(System.currentTimeMillis() - beforeRun);
}
Expand Down
5 changes: 0 additions & 5 deletions edge/src/io/openems/api/controller/ThingMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
*******************************************************************************/
package io.openems.api.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.api.thing.Thing;

public class ThingMap {
protected final Logger log;

private final String id;

public ThingMap(Thing thing) {
log = LoggerFactory.getLogger(this.getClass());
this.id = thing.id();
}

Expand Down
7 changes: 2 additions & 5 deletions edge/src/io/openems/api/device/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.util.Optional;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.openems.api.bridge.Bridge;
import io.openems.api.bridge.BridgeReadTask;
import io.openems.api.bridge.BridgeWriteTask;
Expand All @@ -39,16 +36,16 @@
import io.openems.common.exceptions.OpenemsException;

public abstract class Device implements Thing, ChannelChangeListener {

public final static String THINGID_PREFIX = "_device";

private static int instanceCounter = 0;
protected final Logger log;
private Bridge bridge = null;
private final String thingId;
private ThingStateChannels thingState;

public Device(Bridge parent) throws OpenemsException {
this.thingId = THINGID_PREFIX + instanceCounter++;
log = LoggerFactory.getLogger(this.getClass());
this.bridge = parent;
this.thingState = new ThingStateChannels(this);
}
Expand Down
13 changes: 9 additions & 4 deletions edge/src/io/openems/api/doc/ChannelDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.openems.core.utilities.InjectionUtils;

public class ChannelDoc {

private final Logger log = LoggerFactory.getLogger(ChannelDoc.class);

private final Member member;
Expand All @@ -54,6 +55,7 @@ public class ChannelDoc {
private final Set<Role> readRoles;
private final Set<Role> writeRoles;
private final String defaultValue;
private final String jsonSchema;

public ChannelDoc(Member member, String name, Optional<ChannelInfo> channelInfoOpt) {
this.member = member;
Expand All @@ -77,6 +79,7 @@ public ChannelDoc(Member member, String name, Optional<ChannelInfo> channelInfoO
this.writeRoles = Sets.newHashSet(channelInfo.writeRoles());
this.writeRoles.add(Role.ADMIN);
this.defaultValue = channelInfo.defaultValue();
this.jsonSchema = channelInfo.jsonSchema();
} else {
this.title = ChannelInfo.DEFAULT_TITLE;
this.description = ChannelInfo.DEFAULT_DESCRIPTION;
Expand All @@ -87,6 +90,7 @@ public ChannelDoc(Member member, String name, Optional<ChannelInfo> channelInfoO
this.readRoles = ChannelInfo.DEFAULT_READ_ROLES;
this.writeRoles = ChannelInfo.DEFAULT_WRITE_ROLES;
this.defaultValue = ChannelInfo.DEFAULT_VALUE;
this.jsonSchema = ChannelInfo.DEFAULT_JSON_SCHEMA;
}
}

Expand Down Expand Up @@ -158,14 +162,15 @@ public JsonObject getAsJsonObject() {
}
j.add("writeRoles", jWriteRoles);
j.addProperty("defaultValue", this.defaultValue);
j.addProperty("jsonSchema", this.jsonSchema);
return j;
}

@Override
public String toString() {
return "ChannelDoc [field/method=" + member.getName() + ", name=" + name + ", title=" + title
+ ", description=" + description + ", type=" + typeOpt + ", bitLength=" + bitLengthOpt
+ ", optional=" + optional + ", array=" + array + ", readRoles=" + readRoles + ", writeRoles="
+ writeRoles + ", defaultValue=" + defaultValue + "]";
return "ChannelDoc [field/method=" + member.getName() + ", name=" + name + ", title=" + title + ", description="
+ description + ", type=" + typeOpt + ", bitLength=" + bitLengthOpt + ", optional=" + optional
+ ", array=" + array + ", readRoles=" + readRoles + ", writeRoles=" + writeRoles + ", defaultValue="
+ defaultValue + ", jsonSchema=" + jsonSchema + "]";
}
}
10 changes: 10 additions & 0 deletions edge/src/io/openems/api/doc/ChannelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Role.ADMIN);
public static final Set<Role> DEFAULT_WRITE_ROLES = Sets.newHashSet(Role.ADMIN);
public static final String DEFAULT_VALUE = "";
public static final String DEFAULT_JSON_SCHEMA = "";

String title() default DEFAULT_TITLE;

Expand All @@ -61,6 +62,7 @@
* @return
*/
Role[] readRoles() default { Role.GUEST, Role.OWNER, Role.INSTALLER, Role.ADMIN };

/**
* By default only the "ADMIN" role is allowed to write. ADMIN is added automatically to this list.
*
Expand All @@ -74,4 +76,12 @@
* @return
*/
String defaultValue() default DEFAULT_VALUE;

/**
* Defines the JSON-Schema for this channel. Applies to JsonObject and JsonArray. Schema is based on
* http://json-schema.org
*
* @return
*/
String jsonSchema() default DEFAULT_JSON_SCHEMA;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.openems.api.scheduler;

public interface BeforeControllerExecutedListener {

void beforeControllerExecuted();
}
Loading

0 comments on commit c7fa2eb

Please sign in to comment.