├── .github
├── dependabot.yml
└── workflows
│ └── gradle.yml
├── .gitignore
├── .tool-versions
├── LICENSE.txt
├── README.md
├── build.gradle
├── cli-app
├── build.gradle
├── settings.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── openmuc
│ └── j60870
│ ├── app
│ ├── ConsoleClient.java
│ └── SampleServer.java
│ └── internal
│ └── cli
│ ├── Action.java
│ ├── ActionException.java
│ ├── ActionListener.java
│ ├── ActionProcessor.java
│ ├── CliParameter.java
│ ├── CliParameterBuilder.java
│ ├── CliParseException.java
│ ├── CliParser.java
│ ├── FlagCliParameter.java
│ ├── IntCliParameter.java
│ ├── LongCliParameter.java
│ ├── StringCliParameter.java
│ └── ValueCliParameter.java
├── configuration.gradle
├── docs
├── CHANGELOG.txt
├── images
│ └── banner.png
├── index.html
└── javadoc
│ ├── allclasses-index.html
│ ├── allclasses.html
│ ├── allpackages-index.html
│ ├── constant-values.html
│ ├── deprecated-list.html
│ ├── element-list
│ ├── help-doc.html
│ ├── index-all.html
│ ├── index.html
│ ├── jquery-ui.overrides.css
│ ├── jquery
│ ├── external
│ │ └── jquery
│ │ │ └── jquery.js
│ ├── jquery-3.6.1.min.js
│ ├── jquery-ui.min.css
│ ├── jquery-ui.min.js
│ ├── jszip-utils
│ │ └── dist
│ │ │ ├── jszip-utils-ie.js
│ │ │ ├── jszip-utils-ie.min.js
│ │ │ ├── jszip-utils.js
│ │ │ └── jszip-utils.min.js
│ └── jszip
│ │ └── dist
│ │ ├── jszip.js
│ │ └── jszip.min.js
│ ├── legal
│ ├── ASSEMBLY_EXCEPTION
│ ├── jquery.md
│ ├── jqueryUI.md
│ ├── jszip.md
│ └── pako.md
│ ├── member-search-index.js
│ ├── org
│ └── openmuc
│ │ └── j60870
│ │ ├── ASdu.html
│ │ ├── ASduType.html
│ │ ├── CauseOfTransmission.html
│ │ ├── ClientConnectionBuilder.html
│ │ ├── Connection.html
│ │ ├── ConnectionEventListener.html
│ │ ├── ReservedASduTypeDecoder.html
│ │ ├── Server.Builder.html
│ │ ├── Server.html
│ │ ├── ServerEventListener.html
│ │ ├── Util.html
│ │ ├── ie
│ │ ├── IeAckFileOrSectionQualifier.html
│ │ ├── IeBinaryCounterReading.Flag.html
│ │ ├── IeBinaryCounterReading.html
│ │ ├── IeBinaryStateInformation.html
│ │ ├── IeCauseOfInitialization.html
│ │ ├── IeChecksum.html
│ │ ├── IeDoubleCommand.DoubleCommandState.html
│ │ ├── IeDoubleCommand.html
│ │ ├── IeDoublePointWithQuality.DoublePointInformation.html
│ │ ├── IeDoublePointWithQuality.html
│ │ ├── IeFileReadyQualifier.html
│ │ ├── IeFileSegment.html
│ │ ├── IeFixedTestBitPattern.html
│ │ ├── IeLastSectionOrSegmentQualifier.html
│ │ ├── IeLengthOfFileOrSection.html
│ │ ├── IeNameOfFile.html
│ │ ├── IeNameOfSection.html
│ │ ├── IeNormalizedValue.html
│ │ ├── IeProtectionOutputCircuitInformation.html
│ │ ├── IeProtectionQuality.html
│ │ ├── IeProtectionStartEvent.html
│ │ ├── IeQualifierOfCounterInterrogation.html
│ │ ├── IeQualifierOfInterrogation.html
│ │ ├── IeQualifierOfParameterActivation.html
│ │ ├── IeQualifierOfParameterOfMeasuredValues.html
│ │ ├── IeQualifierOfResetProcessCommand.html
│ │ ├── IeQualifierOfSetPointCommand.html
│ │ ├── IeQuality.html
│ │ ├── IeRegulatingStepCommand.StepCommandState.html
│ │ ├── IeRegulatingStepCommand.html
│ │ ├── IeScaledValue.html
│ │ ├── IeSectionReadyQualifier.html
│ │ ├── IeSelectAndCallQualifier.html
│ │ ├── IeShortFloat.html
│ │ ├── IeSingleCommand.html
│ │ ├── IeSinglePointWithQuality.html
│ │ ├── IeSingleProtectionEvent.EventState.html
│ │ ├── IeSingleProtectionEvent.html
│ │ ├── IeStatusAndStatusChanges.html
│ │ ├── IeStatusOfFile.Flag.html
│ │ ├── IeStatusOfFile.html
│ │ ├── IeTestSequenceCounter.html
│ │ ├── IeTime16.html
│ │ ├── IeTime24.html
│ │ ├── IeTime56.html
│ │ ├── IeValueWithTransientState.html
│ │ ├── InformationElement.html
│ │ ├── InformationObject.html
│ │ ├── package-summary.html
│ │ └── package-tree.html
│ │ ├── package-summary.html
│ │ └── package-tree.html
│ ├── overview-summary.html
│ ├── overview-tree.html
│ ├── package-search-index.js
│ ├── resources
│ ├── glass.png
│ └── x.png
│ ├── script.js
│ ├── search.js
│ ├── stylesheet.css
│ └── type-search-index.js
├── gitlabRelease.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── license
├── LICENSE_HEADER.txt
└── gpl-3.0.txt
├── run-scripts
├── j60870-console-client
├── j60870-console-client.bat
├── j60870-sample-server
└── j60870-sample-server.bat
├── settings.gradle
└── src
├── docs
└── asciidoc
│ ├── common-settings.txt
│ ├── images
│ └── banner.png
│ ├── j60870-doc.adoc
│ ├── openmuc-asciidoc.css
│ └── pdf-theme.yml
├── main
└── java
│ └── org
│ └── openmuc
│ └── j60870
│ ├── APdu.java
│ ├── ASdu.java
│ ├── ASduType.java
│ ├── CauseOfTransmission.java
│ ├── ClientConnectionBuilder.java
│ ├── CommonBuilder.java
│ ├── Connection.java
│ ├── ConnectionEventListener.java
│ ├── ConnectionSettings.java
│ ├── ReservedASduTypeDecoder.java
│ ├── Server.java
│ ├── ServerEventListener.java
│ ├── ServerThread.java
│ ├── TimeoutManager.java
│ ├── TimeoutTask.java
│ ├── UnknownAsduTypeException.java
│ ├── Util.java
│ ├── ie
│ ├── IeAbstractQualifierOfCommand.java
│ ├── IeAbstractQuality.java
│ ├── IeAckFileOrSectionQualifier.java
│ ├── IeBinaryCounterReading.java
│ ├── IeBinaryStateInformation.java
│ ├── IeCauseOfInitialization.java
│ ├── IeChecksum.java
│ ├── IeDoubleCommand.java
│ ├── IeDoublePointWithQuality.java
│ ├── IeFileReadyQualifier.java
│ ├── IeFileSegment.java
│ ├── IeFixedTestBitPattern.java
│ ├── IeLastSectionOrSegmentQualifier.java
│ ├── IeLengthOfFileOrSection.java
│ ├── IeNameOfFile.java
│ ├── IeNameOfSection.java
│ ├── IeNormalizedValue.java
│ ├── IeProtectionOutputCircuitInformation.java
│ ├── IeProtectionQuality.java
│ ├── IeProtectionStartEvent.java
│ ├── IeQualifierOfCounterInterrogation.java
│ ├── IeQualifierOfInterrogation.java
│ ├── IeQualifierOfParameterActivation.java
│ ├── IeQualifierOfParameterOfMeasuredValues.java
│ ├── IeQualifierOfResetProcessCommand.java
│ ├── IeQualifierOfSetPointCommand.java
│ ├── IeQuality.java
│ ├── IeRegulatingStepCommand.java
│ ├── IeScaledValue.java
│ ├── IeSectionReadyQualifier.java
│ ├── IeSelectAndCallQualifier.java
│ ├── IeShortFloat.java
│ ├── IeSingleCommand.java
│ ├── IeSinglePointWithQuality.java
│ ├── IeSingleProtectionEvent.java
│ ├── IeStatusAndStatusChanges.java
│ ├── IeStatusOfFile.java
│ ├── IeTestSequenceCounter.java
│ ├── IeTime16.java
│ ├── IeTime24.java
│ ├── IeTime56.java
│ ├── IeValueWithTransientState.java
│ ├── InformationElement.java
│ ├── InformationObject.java
│ └── package-info.java
│ └── internal
│ ├── ByteStreamHelper.java
│ ├── ExtendedDataInputStream.java
│ ├── HexUtils.java
│ ├── SerialExecutor.java
│ └── StartBytesSimpleReader.java
└── test
└── java
└── org
└── openmuc
└── j60870
├── ClientServerITest.java
├── CloseThenAckITest.java
├── CommonBuilderTest.java
├── TestUtils.java
├── TimeoutManagerTest.java
├── UtilTest.java
├── WrongTypeIdITest.java
└── ie
├── CP56Time2aTest.java
├── IeBinaryCounterReadingTest.java
├── IeBinaryStateInformationTest.java
├── IeTestSequenceCounterTest.java
├── IeValueWithTransientTest.java
└── TransmissionControlUsingStartStopTest.java
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "github-actions"
9 | # Workflow files stored in the
10 | # default location of `.github/workflows`
11 | directory: "/"
12 | schedule:
13 | interval: "daily"
14 |
--------------------------------------------------------------------------------
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | name: Java CI with Gradle
2 |
3 | on:
4 | push:
5 | branches: [ "master" ]
6 | pull_request:
7 | branches: [ "master" ]
8 |
9 | permissions:
10 | contents: read
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 |
16 | steps:
17 | - uses: actions/checkout@v4
18 | - name: Set up JDK 11
19 | uses: actions/setup-java@v4.7.1
20 | with:
21 | java-version: "11"
22 | distribution: "temurin"
23 | - name: Setup Gradle
24 | uses: gradle/actions/setup-gradle@v4
25 | - uses: actions/cache@v4
26 | with:
27 | path: |
28 | ~/.gradle/caches
29 | ~/.gradle/wrapper
30 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
31 | restore-keys: |
32 | ${{ runner.os }}-gradle-
33 | - name: Build with Gradle
34 | run: ./gradlew build
35 |
--------------------------------------------------------------------------------
/.tool-versions:
--------------------------------------------------------------------------------
1 | java temurin-11.0.23+9
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IEC 60870-5-104
2 |
3 | ## Overview [](https://github.com/gythialy/j60870/actions/workflows/gradle.yml)
4 |
5 | This is UNOFFICIAL, fork from [openmuc](https://www.openmuc.org/iec-60870-5-104/).
6 |
7 | j60870 is a library implementing the IEC 60870-5-104 communication standard. The library can be used to program clients
8 | as well as servers. j60870 is licensed under the GPLv3. In addition we sell j60870 under proprietary licenses if needed.
9 | Please contact us if you need another license. Proprietary licenses are negotiated individually.
10 |
11 | Read the [user guide](https://gythialy.github.io/j60870/) on how to get started with the library.
12 |
--------------------------------------------------------------------------------
/cli-app/build.gradle:
--------------------------------------------------------------------------------
1 | eclipse.project.name = 'j60870-cli-app'
2 |
3 | dependencies {
4 | compile project(':')
5 | }
6 |
--------------------------------------------------------------------------------
/cli-app/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'j60870-cli-app'
2 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/Action.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class Action {
24 |
25 | private final String key;
26 | private final String description;
27 |
28 | public Action(String key, String description) {
29 | this.key = key;
30 | this.description = description;
31 | }
32 |
33 | public String getKey() {
34 | return key;
35 | }
36 |
37 | public String getDescription() {
38 | return description;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/ActionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public final class ActionException extends Exception {
24 |
25 | private static final long serialVersionUID = 4806947065917148946L;
26 |
27 | public ActionException() {
28 | super();
29 | }
30 |
31 | public ActionException(String s) {
32 | super(s);
33 | }
34 |
35 | public ActionException(Throwable cause) {
36 | super(cause);
37 | }
38 |
39 | public ActionException(String s, Throwable cause) {
40 | super(s, cause);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/ActionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public interface ActionListener {
24 |
25 | public void actionCalled(String actionKey) throws ActionException;
26 |
27 | public void quit();
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/ActionProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | import java.io.BufferedReader;
24 | import java.io.IOException;
25 | import java.io.InputStreamReader;
26 | import java.util.LinkedHashMap;
27 | import java.util.Map;
28 |
29 | import static java.lang.System.exit;
30 | import static java.lang.System.out;
31 |
32 | public class ActionProcessor {
33 |
34 | private static final String SEPARATOR_LINE = "------------------------------------------------------";
35 |
36 | private final BufferedReader reader;
37 | private final ActionListener actionListener;
38 |
39 | private final Map actionMap = new LinkedHashMap<>();
40 |
41 | private final Action helpAction = new Action("h", "print help message");
42 | private final Action quitAction = new Action("q", "quit the application");
43 |
44 | public ActionProcessor(ActionListener actionListener) {
45 | reader = new BufferedReader(new InputStreamReader(System.in));
46 | this.actionListener = actionListener;
47 | }
48 |
49 | public void addAction(Action action) {
50 | actionMap.put(action.getKey(), action);
51 | }
52 |
53 | public BufferedReader getReader() {
54 | return reader;
55 | }
56 |
57 | public void start() {
58 |
59 | actionMap.put(helpAction.getKey(), helpAction);
60 | actionMap.put(quitAction.getKey(), quitAction);
61 |
62 | printHelp();
63 |
64 | try {
65 |
66 | String actionKey;
67 | while (true) {
68 | System.out.println("\n** Enter action key: ");
69 |
70 | try {
71 | actionKey = reader.readLine();
72 | } catch (IOException e) {
73 | System.err.printf("%s. Application is being shut down.%n", e.getMessage());
74 | exit(2);
75 | return;
76 | }
77 |
78 | if (actionMap.get(actionKey) == null) {
79 | System.err.println("Illegal action key.\n");
80 | printHelp();
81 | continue;
82 | }
83 |
84 | if (actionKey.equals(helpAction.getKey())) {
85 | printHelp();
86 | continue;
87 | }
88 |
89 | if (actionKey.equals(quitAction.getKey())) {
90 | actionListener.quit();
91 | return;
92 | }
93 |
94 | actionListener.actionCalled(actionKey);
95 |
96 | }
97 |
98 | } catch (Exception e) {
99 | e.printStackTrace();
100 | actionListener.quit();
101 | } finally {
102 | close();
103 | }
104 | }
105 |
106 | private void printHelp() {
107 | final String message = " %s - %s%n";
108 | out.flush();
109 | out.println();
110 | out.println(SEPARATOR_LINE);
111 |
112 | for (Action action : actionMap.values()) {
113 | out.printf(message, action.getKey(), action.getDescription());
114 | }
115 |
116 | out.println(SEPARATOR_LINE);
117 |
118 | }
119 |
120 | public void close() {
121 | try {
122 | reader.close();
123 | } catch (IOException e) {
124 | }
125 |
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/CliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public abstract class CliParameter {
24 |
25 | final String name;
26 | final String description;
27 | final boolean optional;
28 | boolean selected;
29 |
30 | CliParameter(CliParameterBuilder builder) {
31 | name = builder.name;
32 | description = builder.description;
33 | optional = builder.optional;
34 | }
35 |
36 | /**
37 | * @return the name
38 | */
39 | public String getName() {
40 | return name;
41 | }
42 |
43 | /**
44 | * @return the description
45 | */
46 | public String getDescription() {
47 | return description;
48 | }
49 |
50 | /**
51 | * @return the optional
52 | */
53 | public boolean isOptional() {
54 | return optional;
55 | }
56 |
57 | public boolean isSelected() {
58 | return selected;
59 | }
60 |
61 | abstract int parse(String[] args, int i) throws CliParseException;
62 |
63 | abstract int appendSynopsis(StringBuilder sb);
64 |
65 | abstract void appendDescription(StringBuilder sb);
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/CliParameterBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class CliParameterBuilder {
24 |
25 | final String name;
26 | String description;
27 | boolean optional = true;
28 |
29 | public CliParameterBuilder(String name) {
30 | this.name = name;
31 | }
32 |
33 | public CliParameterBuilder setDescription(String description) {
34 | this.description = description;
35 | return this;
36 | }
37 |
38 | public CliParameterBuilder setMandatory() {
39 | optional = false;
40 | return this;
41 | }
42 |
43 | public LongCliParameter buildLongParameter(String parameterName, long defaultValue) {
44 | return new LongCliParameter(this, parameterName, defaultValue);
45 | }
46 |
47 | public LongCliParameter buildLongParameter(String parameterName) {
48 | return new LongCliParameter(this, parameterName);
49 | }
50 |
51 | public IntCliParameter buildIntParameter(String parameterName, int defaultValue) {
52 | return new IntCliParameter(this, parameterName, defaultValue);
53 | }
54 |
55 | public IntCliParameter buildIntParameter(String parameterName) {
56 | return new IntCliParameter(this, parameterName);
57 | }
58 |
59 | public StringCliParameter buildStringParameter(String parameterName, String defaultValue) {
60 | return new StringCliParameter(this, parameterName, defaultValue);
61 | }
62 |
63 | public StringCliParameter buildStringParameter(String parameterName) {
64 | return new StringCliParameter(this, parameterName);
65 | }
66 |
67 | public FlagCliParameter buildFlagParameter() {
68 | return new FlagCliParameter(this);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/CliParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public final class CliParseException extends Exception {
24 |
25 | private static final long serialVersionUID = -5162894897245715377L;
26 |
27 | public CliParseException() {
28 | super();
29 | }
30 |
31 | public CliParseException(String s) {
32 | super(s);
33 | }
34 |
35 | public CliParseException(Throwable cause) {
36 | super(cause);
37 | }
38 |
39 | public CliParseException(String s, Throwable cause) {
40 | super(s, cause);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/FlagCliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class FlagCliParameter extends CliParameter {
24 |
25 | FlagCliParameter(CliParameterBuilder builder) {
26 | super(builder);
27 | }
28 |
29 | @Override
30 | int appendSynopsis(StringBuilder sb) {
31 | int length = 0;
32 | if (optional) {
33 | sb.append("[");
34 | length++;
35 | }
36 | sb.append(name);
37 | length += name.length();
38 | if (optional) {
39 | sb.append("]");
40 | length++;
41 | }
42 | return length;
43 | }
44 |
45 | @Override
46 | void appendDescription(StringBuilder sb) {
47 | sb.append("\t").append(name).append("\n\t ").append(description);
48 | }
49 |
50 | @Override
51 | int parse(String[] args, int i) throws CliParseException {
52 | selected = true;
53 | return 1;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/IntCliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class IntCliParameter extends ValueCliParameter {
24 |
25 | Integer value;
26 |
27 | IntCliParameter(CliParameterBuilder builder, String parameterName, int defaultValue) {
28 | super(builder, parameterName);
29 | value = defaultValue;
30 | }
31 |
32 | IntCliParameter(CliParameterBuilder builder, String parameterName) {
33 | super(builder, parameterName);
34 | }
35 |
36 | public int getValue() {
37 | return value;
38 | }
39 |
40 | @Override
41 | int parse(String[] args, int i) throws CliParseException {
42 | selected = true;
43 |
44 | if (args.length < (i + 2)) {
45 | throw new CliParseException("Parameter " + name + " has no value.");
46 | }
47 |
48 | try {
49 | value = Integer.decode(args[i + 1]);
50 | } catch (Exception e) {
51 | throw new CliParseException("Parameter value " + args[i + 1] + " cannot be converted to int.");
52 | }
53 | return 2;
54 | }
55 |
56 | @Override
57 | void appendDescription(StringBuilder sb) {
58 | super.appendDescription(sb);
59 | if (value != null) {
60 | sb.append(" Default is ").append(value).append(".");
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/LongCliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class LongCliParameter extends ValueCliParameter {
24 |
25 | Long value;
26 |
27 | LongCliParameter(CliParameterBuilder builder, String parameterName, long defaultValue) {
28 | super(builder, parameterName);
29 | value = defaultValue;
30 | }
31 |
32 | LongCliParameter(CliParameterBuilder builder, String parameterName) {
33 | super(builder, parameterName);
34 | }
35 |
36 | public long getValue() {
37 | return value;
38 | }
39 |
40 | @Override
41 | int parse(String[] args, int i) throws CliParseException {
42 | selected = true;
43 |
44 | if (args.length < (i + 2)) {
45 | throw new CliParseException("Parameter " + name + " has no value.");
46 | }
47 |
48 | try {
49 | value = Long.decode(args[i + 1]);
50 | } catch (Exception e) {
51 | throw new CliParseException("Parameter value " + args[i + 1] + " cannot be converted to long.");
52 | }
53 | return 2;
54 | }
55 |
56 | @Override
57 | void appendDescription(StringBuilder sb) {
58 | super.appendDescription(sb);
59 | if (value != null) {
60 | sb.append(" Default is ").append(value).append(".");
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/StringCliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | public class StringCliParameter extends ValueCliParameter {
24 |
25 | String value;
26 |
27 | StringCliParameter(CliParameterBuilder builder, String parameterName, String defaultValue) {
28 | super(builder, parameterName);
29 | value = defaultValue;
30 | }
31 |
32 | StringCliParameter(CliParameterBuilder builder, String parameterName) {
33 | super(builder, parameterName);
34 | }
35 |
36 | public String getValue() {
37 | return value;
38 | }
39 |
40 | @Override
41 | int parse(String[] args, int i) throws CliParseException {
42 | selected = true;
43 |
44 | if (args.length < (i + 2)) {
45 | throw new CliParseException("Parameter " + name + " has no value.");
46 | }
47 | value = args[i + 1];
48 |
49 | return 2;
50 | }
51 |
52 | @Override
53 | public void appendDescription(StringBuilder sb) {
54 | super.appendDescription(sb);
55 | if (value != null) {
56 | sb.append(" Default is ").append(value).append(".");
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/cli-app/src/main/java/org/openmuc/j60870/internal/cli/ValueCliParameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal.cli;
22 |
23 | abstract class ValueCliParameter extends CliParameter {
24 |
25 | String parameterName;
26 |
27 | ValueCliParameter(CliParameterBuilder builder, String parameterName) {
28 | super(builder);
29 | this.parameterName = parameterName;
30 | }
31 |
32 | @Override
33 | int appendSynopsis(StringBuilder sb) {
34 | int length = 0;
35 | if (optional) {
36 | sb.append("[");
37 | length++;
38 | }
39 | sb.append(name).append(" <").append(parameterName).append(">");
40 | length += (name.length() + 3 + parameterName.length());
41 | if (optional) {
42 | sb.append("]");
43 | length++;
44 | }
45 | return length;
46 | }
47 |
48 | @Override
49 | void appendDescription(StringBuilder sb) {
50 | sb.append("\t").append(name).append(" <").append(parameterName).append(">\n\t ").append(description);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/configuration.gradle:
--------------------------------------------------------------------------------
1 | project.ext {
2 |
3 | cfgVersion = "1.7.2"
4 |
5 | cfgGroup = "org.openmuc"
6 |
7 | cfgCopyDependencies = false
8 |
9 | cfgCopyToRoot = false
10 |
11 | cfgSignPom = true
12 |
13 | cfgRepository = project.properties.sonatypeRepository
14 |
15 | cfgSnapshotRepository = project.properties.sonatypeSnapshotRepository
16 |
17 | cfgRepositoryUser = project.properties.sonatypeUser
18 |
19 | cfgRepositoryPass = project.properties.sonatypePass
20 |
21 | javaProjects = allprojects
22 |
23 | distributionProjects = allprojects.findAll {
24 | it.getPath() == ":cli-app" ||
25 | it.getPath() == ":"
26 | }
27 |
28 | repositoryProjects = allprojects.findAll {
29 | it.getPath() == ":"
30 | }
31 |
32 | docProjects = distributionProjects
33 | }
34 |
35 | tasks.withType(Tar) {
36 |
37 | into(project.name) {
38 | from("./") {
39 | include "*.gradle"
40 | include "license/**"
41 | include "doc/CHANGELOG.txt"
42 | include "run-scripts/**"
43 | include "gradle/wrapper/**"
44 | include "gradlew"
45 | include "gradlew.bat"
46 | include "build/libs/**"
47 | include "src/**"
48 | include "cli-app/**"
49 | }
50 |
51 | if (name.equals("tar")) {
52 | exclude "**/dependencies/**/src"
53 | exclude "**/bin"
54 | exclude "**/.project"
55 | exclude "**/.classpath"
56 | exclude "**/.gradle"
57 | exclude "**/.settings"
58 | exclude "gitlabRelease.gradle"
59 |
60 | }
61 |
62 | from("./build/") {
63 | include "settings.gradle"
64 | }
65 | }
66 |
67 | into(project.name + "/doc/user-guide/") {
68 | from("./build/asciidoc/html5/") {
69 | include "**"
70 | }
71 | from("./build/asciidoc/pdf/") {
72 | include "*.pdf"
73 | }
74 | }
75 |
76 | into(project.name + "/doc/") {
77 | from("./build/docs/") {
78 | include "javadoc/**"
79 | }
80 | }
81 |
82 | }
83 |
84 |
85 | //------------------project specific configurations--------------------
86 |
87 | apply plugin: "java"
88 | apply plugin: "eclipse"
89 | apply plugin: "osgi"
90 | apply plugin: "maven"
91 | apply plugin: "signing"
92 |
93 | dependencies {
94 | testCompile group: "org.powermock", name: "powermock-module-junit4", version: "1.6.4"
95 | testCompile group: "org.powermock", name: "powermock-api-mockito", version: "1.6.4"
96 | testCompile group: "pl.pragmatists", name: "JUnitParams", version: "1.1.0"
97 | testCompile group: "org.awaitility", name: "awaitility-proxy", version: "3.1.3"
98 | }
99 |
100 | jar {
101 | manifest {
102 | name = "j60870"
103 | instruction "Export-Package", "!org.openmuc.j60870.internal.internal.*,*"
104 | }
105 | }
106 |
107 | if (JavaVersion.current().isJava8Compatible()) {
108 | allprojects {
109 | tasks.withType(Javadoc) {
110 | options.addStringOption('Xdoclint:none', '-quiet')
111 | }
112 | }
113 | }
114 |
115 | uploadArchives {
116 | repositories {
117 | mavenDeployer {
118 | pom.project {
119 | name "j60870"
120 | description "j60870 is an IEC 60870-5-104 client and server library."
121 |
122 | licenses {
123 | license {
124 | name "GNU General Public License"
125 | url "http://www.gnu.org/copyleft/gpl-3.0.html"
126 | distribution "repo"
127 | }
128 | }
129 |
130 | }
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/docs/images/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gythialy/j60870/c4619c98cfbddecc1328c848f55504f89a27b029/docs/images/banner.png
--------------------------------------------------------------------------------
/docs/javadoc/element-list:
--------------------------------------------------------------------------------
1 | org.openmuc.j60870
2 | org.openmuc.j60870.ie
3 |
--------------------------------------------------------------------------------
/docs/javadoc/jquery-ui.overrides.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | .ui-state-active,
27 | .ui-widget-content .ui-state-active,
28 | .ui-widget-header .ui-state-active,
29 | a.ui-button:active,
30 | .ui-button:active,
31 | .ui-button.ui-state-active:hover {
32 | /* Overrides the color of selection used in jQuery UI */
33 | background: #F8981D;
34 | border: 1px solid #F8981D;
35 | }
36 |
--------------------------------------------------------------------------------
/docs/javadoc/jquery/jquery-ui.min.css:
--------------------------------------------------------------------------------
1 | /*! jQuery UI - v1.13.2 - 2023-02-27
2 | * http://jqueryui.com
3 | * Includes: core.css, autocomplete.css, menu.css
4 | * Copyright jQuery Foundation and other contributors; Licensed MIT */
5 |
6 | .ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;-ms-filter:"alpha(opacity=0)"}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important;pointer-events:none}.ui-icon{display:inline-block;vertical-align:middle;margin-top:-.25em;position:relative;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-icon-block{left:50%;margin-left:-8px;display:block}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{margin:0;cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-item-wrapper{position:relative;padding:3px 1em 3px .4em}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item-wrapper{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}
--------------------------------------------------------------------------------
/docs/javadoc/jquery/jszip-utils/dist/jszip-utils-ie.js:
--------------------------------------------------------------------------------
1 | /*!
2 |
3 | JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
4 |
5 |
6 | (c) 2014 Stuart Knightley, David Duponchel
7 | Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown.
8 |
9 | */
10 | ;(function e(t, n, r) {
11 | function s(o, u) {
12 | if (!n[o]) {
13 | if (!t[o]) {
14 | var a = typeof require == "function" && require;
15 | if (!u && a) return a(o, !0);
16 | if (i) return i(o, !0);
17 | throw new Error("Cannot find module '" + o + "'")
18 | }
19 | var f = n[o] = {exports: {}};
20 | t[o][0].call(f.exports, function (e) {
21 | var n = t[o][1][e];
22 | return s(n ? n : e)
23 | }, f, f.exports, e, t, n, r)
24 | }
25 | return n[o].exports
26 | }
27 |
28 | var i = typeof require == "function" && require;
29 | for (var o = 0; o < r.length; o++) s(r[o]);
30 | return s
31 | })({
32 | 1: [function (require, module, exports) {
33 | var global = typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};/* jshint evil: true, newcap: false */
34 | /* global IEBinaryToArray_ByteStr, IEBinaryToArray_ByteStr_Last */
35 | "use strict";
36 |
37 | // Adapted from http://stackoverflow.com/questions/1095102/how-do-i-load-binary-image-data-using-javascript-and-xmlhttprequest
38 | var IEBinaryToArray_ByteStr_Script =
39 | "\r\n" +
40 | "\r\n";
54 |
55 | // inject VBScript
56 | document.write(IEBinaryToArray_ByteStr_Script);
57 |
58 | global.JSZipUtils._getBinaryFromXHR = function (xhr) {
59 | var binary = xhr.responseBody;
60 | var byteMapping = {};
61 | for (var i = 0; i < 256; i++) {
62 | for (var j = 0; j < 256; j++) {
63 | byteMapping[String.fromCharCode(i + (j << 8))] =
64 | String.fromCharCode(i) + String.fromCharCode(j);
65 | }
66 | }
67 | var rawBytes = IEBinaryToArray_ByteStr(binary);
68 | var lastChr = IEBinaryToArray_ByteStr_Last(binary);
69 | return rawBytes.replace(/[\s\S]/g, function (match) {
70 | return byteMapping[match];
71 | }) + lastChr;
72 | };
73 |
74 | // enforcing Stuk's coding style
75 | // vim: set shiftwidth=4 softtabstop=4:
76 |
77 | }, {}]
78 | }, {}, [1])
79 | ;
80 |
--------------------------------------------------------------------------------
/docs/javadoc/jquery/jszip-utils/dist/jszip-utils-ie.min.js:
--------------------------------------------------------------------------------
1 | /*!
2 |
3 | JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
4 |
5 |
6 | (c) 2014 Stuart Knightley, David Duponchel
7 | Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown.
8 |
9 | */
10 | !function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g\r\n\r\n";document.write(b),a.JSZipUtils._getBinaryFromXHR=function(a){for(var b=a.responseBody,c={},d=0;256>d;d++)for(var e=0;256>e;e++)c[String.fromCharCode(d+(e<<8))]=String.fromCharCode(d)+String.fromCharCode(e);var f=IEBinaryToArray_ByteStr(b),g=IEBinaryToArray_ByteStr_Last(b);return f.replace(/[\s\S]/g,function(a){return c[a]})+g}},{}]},{},[1]);
11 |
--------------------------------------------------------------------------------
/docs/javadoc/jquery/jszip-utils/dist/jszip-utils.min.js:
--------------------------------------------------------------------------------
1 | /*!
2 |
3 | JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
4 |
5 |
6 | (c) 2014 Stuart Knightley, David Duponchel
7 | Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown.
8 |
9 | */
10 | !function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.JSZipUtils=a():"undefined"!=typeof global?global.JSZipUtils=a():"undefined"!=typeof self&&(self.JSZipUtils=a())}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g version 2
7 | only ("GPL2"), with the following clarification and special exception.
8 |
9 | Linking this OpenJDK Code statically or dynamically with other code
10 | is making a combined work based on this library. Thus, the terms
11 | and conditions of GPL2 cover the whole combination.
12 |
13 | As a special exception, Oracle gives you permission to link this
14 | OpenJDK Code with certain code licensed by Oracle as indicated at
15 | http://openjdk.java.net/legal/exception-modules-2007-05-08.html
16 | ("Designated Exception Modules") to produce an executable,
17 | regardless of the license terms of the Designated Exception Modules,
18 | and to copy and distribute the resulting executable under GPL2,
19 | provided that the Designated Exception Modules continue to be
20 | governed by the licenses under which they were offered by Oracle.
21 |
22 | As such, it allows licensees and sublicensees of Oracle's GPL2 OpenJDK Code
23 | to build an executable that includes those portions of necessary code that
24 | Oracle could not provide under GPL2 (or that Oracle has provided under GPL2
25 | with the Classpath exception). If you modify or add to the OpenJDK code,
26 | that new GPL2 code may still be combined with Designated Exception Modules
27 | if the new code is made subject to this exception by its copyright holder.
28 |
--------------------------------------------------------------------------------
/docs/javadoc/legal/jquery.md:
--------------------------------------------------------------------------------
1 | ## jQuery v3.6.1
2 |
3 | ### jQuery License
4 |
5 | ```
6 | jQuery v 3.6.1
7 | Copyright OpenJS Foundation and other contributors, https://openjsf.org/
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining
10 | a copy of this software and associated documentation files (the
11 | "Software"), to deal in the Software without restriction, including
12 | without limitation the rights to use, copy, modify, merge, publish,
13 | distribute, sublicense, and/or sell copies of the Software, and to
14 | permit persons to whom the Software is furnished to do so, subject to
15 | the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be
18 | included in all copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 |
28 | ******************************************
29 |
30 | The jQuery JavaScript Library v3.6.1 also includes Sizzle.js
31 |
32 | Sizzle.js includes the following license:
33 |
34 | Copyright JS Foundation and other contributors, https://js.foundation/
35 |
36 | This software consists of voluntary contributions made by many
37 | individuals. For exact contribution history, see the revision history
38 | available at https://github.com/jquery/sizzle
39 |
40 | The following license applies to all parts of this software except as
41 | documented below:
42 |
43 | ====
44 |
45 | Permission is hereby granted, free of charge, to any person obtaining
46 | a copy of this software and associated documentation files (the
47 | "Software"), to deal in the Software without restriction, including
48 | without limitation the rights to use, copy, modify, merge, publish,
49 | distribute, sublicense, and/or sell copies of the Software, and to
50 | permit persons to whom the Software is furnished to do so, subject to
51 | the following conditions:
52 |
53 | The above copyright notice and this permission notice shall be
54 | included in all copies or substantial portions of the Software.
55 |
56 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
57 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
59 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
60 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
61 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
62 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
63 |
64 | ====
65 |
66 | All files located in the node_modules and external directories are
67 | externally maintained libraries used by this software which have their
68 | own licenses; we recommend you read them, as their terms may differ from
69 | the terms above.
70 |
71 | *********************
72 |
73 | ```
74 |
--------------------------------------------------------------------------------
/docs/javadoc/legal/jqueryUI.md:
--------------------------------------------------------------------------------
1 | ## jQuery UI v1.13.2
2 |
3 | ### jQuery UI License
4 |
5 | ```
6 | Copyright jQuery Foundation and other contributors, https://jquery.org/
7 |
8 | This software consists of voluntary contributions made by many
9 | individuals. For exact contribution history, see the revision history
10 | available at https://github.com/jquery/jquery-ui
11 |
12 | The following license applies to all parts of this software except as
13 | documented below:
14 |
15 | ====
16 |
17 | Permission is hereby granted, free of charge, to any person obtaining
18 | a copy of this software and associated documentation files (the
19 | "Software"), to deal in the Software without restriction, including
20 | without limitation the rights to use, copy, modify, merge, publish,
21 | distribute, sublicense, and/or sell copies of the Software, and to
22 | permit persons to whom the Software is furnished to do so, subject to
23 | the following conditions:
24 |
25 | The above copyright notice and this permission notice shall be
26 | included in all copies or substantial portions of the Software.
27 |
28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 |
36 | ====
37 |
38 | Copyright and related rights for sample code are waived via CC0. Sample
39 | code is defined as all source code contained within the demos directory.
40 |
41 | CC0: http://creativecommons.org/publicdomain/zero/1.0/
42 |
43 | ====
44 |
45 | All files located in the node_modules and external directories are
46 | externally maintained libraries used by this software which have their
47 | own licenses; we recommend you read them, as their terms may differ from
48 | the terms above.
49 |
50 | ```
51 |
--------------------------------------------------------------------------------
/docs/javadoc/legal/pako.md:
--------------------------------------------------------------------------------
1 | ## Pako v1.0
2 |
3 | ### Pako License
4 |
5 |
6 | Copyright (C) 2014-2017 by Vitaly Puzrin and Andrei Tuputcyn
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 | (C) 1995-2013 Jean-loup Gailly and Mark Adler
26 | (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
27 |
28 | This software is provided 'as-is', without any express or implied
29 | warranty. In no event will the authors be held liable for any damages
30 | arising from the use of this software.
31 |
32 | Permission is granted to anyone to use this software for any purpose,
33 | including commercial applications, and to alter it and redistribute it
34 | freely, subject to the following restrictions:
35 |
36 | 1. The origin of this software must not be misrepresented; you must not
37 | claim that you wrote the original software. If you use this software
38 | in a product, an acknowledgment in the product documentation would be
39 | appreciated but is not required.
40 | 2. Altered source versions must be plainly marked as such, and must not be
41 | misrepresented as being the original software.
42 | 3. This notice may not be removed or altered from any source distribution.
43 |
44 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/javadoc/package-search-index.js:
--------------------------------------------------------------------------------
1 | packageSearchIndex = [{
2 | "l": "All Packages",
3 | "url": "allpackages-index.html"
4 | }, {"l": "org.openmuc.j60870"}, {"l": "org.openmuc.j60870.ie"}]
5 |
--------------------------------------------------------------------------------
/docs/javadoc/resources/glass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gythialy/j60870/c4619c98cfbddecc1328c848f55504f89a27b029/docs/javadoc/resources/glass.png
--------------------------------------------------------------------------------
/docs/javadoc/resources/x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gythialy/j60870/c4619c98cfbddecc1328c848f55504f89a27b029/docs/javadoc/resources/x.png
--------------------------------------------------------------------------------
/docs/javadoc/type-search-index.js:
--------------------------------------------------------------------------------
1 | typeSearchIndex = [{"l":"All Classes","url":"allclasses-index.html"},{"p":"org.openmuc.j60870","l":"ASdu"},{"p":"org.openmuc.j60870","l":"ASduType"},{"p":"org.openmuc.j60870","l":"Server.Builder"},{"p":"org.openmuc.j60870","l":"CauseOfTransmission"},{"p":"org.openmuc.j60870","l":"ClientConnectionBuilder"},{"p":"org.openmuc.j60870","l":"Connection"},{"p":"org.openmuc.j60870","l":"ConnectionEventListener"},{"p":"org.openmuc.j60870.ie","l":"IeDoubleCommand.DoubleCommandState"},{"p":"org.openmuc.j60870.ie","l":"IeDoublePointWithQuality.DoublePointInformation"},{"p":"org.openmuc.j60870.ie","l":"IeSingleProtectionEvent.EventState"},{"p":"org.openmuc.j60870.ie","l":"IeBinaryCounterReading.Flag"},{"p":"org.openmuc.j60870.ie","l":"IeStatusOfFile.Flag"},{"p":"org.openmuc.j60870.ie","l":"IeAckFileOrSectionQualifier"},{"p":"org.openmuc.j60870.ie","l":"IeBinaryCounterReading"},{"p":"org.openmuc.j60870.ie","l":"IeBinaryStateInformation"},{"p":"org.openmuc.j60870.ie","l":"IeCauseOfInitialization"},{"p":"org.openmuc.j60870.ie","l":"IeChecksum"},{"p":"org.openmuc.j60870.ie","l":"IeDoubleCommand"},{"p":"org.openmuc.j60870.ie","l":"IeDoublePointWithQuality"},{"p":"org.openmuc.j60870.ie","l":"IeFileReadyQualifier"},{"p":"org.openmuc.j60870.ie","l":"IeFileSegment"},{"p":"org.openmuc.j60870.ie","l":"IeFixedTestBitPattern"},{"p":"org.openmuc.j60870.ie","l":"IeLastSectionOrSegmentQualifier"},{"p":"org.openmuc.j60870.ie","l":"IeLengthOfFileOrSection"},{"p":"org.openmuc.j60870.ie","l":"IeNameOfFile"},{"p":"org.openmuc.j60870.ie","l":"IeNameOfSection"},{"p":"org.openmuc.j60870.ie","l":"IeNormalizedValue"},{"p":"org.openmuc.j60870.ie","l":"IeProtectionOutputCircuitInformation"},{"p":"org.openmuc.j60870.ie","l":"IeProtectionQuality"},{"p":"org.openmuc.j60870.ie","l":"IeProtectionStartEvent"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfCounterInterrogation"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfInterrogation"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfParameterActivation"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfParameterOfMeasuredValues"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfResetProcessCommand"},{"p":"org.openmuc.j60870.ie","l":"IeQualifierOfSetPointCommand"},{"p":"org.openmuc.j60870.ie","l":"IeQuality"},{"p":"org.openmuc.j60870.ie","l":"IeRegulatingStepCommand"},{"p":"org.openmuc.j60870.ie","l":"IeScaledValue"},{"p":"org.openmuc.j60870.ie","l":"IeSectionReadyQualifier"},{"p":"org.openmuc.j60870.ie","l":"IeSelectAndCallQualifier"},{"p":"org.openmuc.j60870.ie","l":"IeShortFloat"},{"p":"org.openmuc.j60870.ie","l":"IeSingleCommand"},{"p":"org.openmuc.j60870.ie","l":"IeSinglePointWithQuality"},{"p":"org.openmuc.j60870.ie","l":"IeSingleProtectionEvent"},{"p":"org.openmuc.j60870.ie","l":"IeStatusAndStatusChanges"},{"p":"org.openmuc.j60870.ie","l":"IeStatusOfFile"},{"p":"org.openmuc.j60870.ie","l":"IeTestSequenceCounter"},{"p":"org.openmuc.j60870.ie","l":"IeTime16"},{"p":"org.openmuc.j60870.ie","l":"IeTime24"},{"p":"org.openmuc.j60870.ie","l":"IeTime56"},{"p":"org.openmuc.j60870.ie","l":"IeValueWithTransientState"},{"p":"org.openmuc.j60870.ie","l":"InformationElement"},{"p":"org.openmuc.j60870.ie","l":"InformationObject"},{"p":"org.openmuc.j60870","l":"ReservedASduTypeDecoder"},{"p":"org.openmuc.j60870","l":"Server"},{"p":"org.openmuc.j60870","l":"ServerEventListener"},{"p":"org.openmuc.j60870.ie","l":"IeRegulatingStepCommand.StepCommandState"},{"p":"org.openmuc.j60870","l":"Util"}]
--------------------------------------------------------------------------------
/gitlabRelease.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "maven-publish"
2 | apply plugin: "java"
3 |
4 | def tokenName = 'Private-Token'
5 | def tokenValue = ''
6 |
7 | if (project.hasProperty("gitLabPrivateToken")) {
8 | tokenValue = gitLabPrivateToken
9 | }
10 | if (System.getenv("CI")) {
11 | tokenName = 'Job-Token'
12 | tokenValue = System.getenv("CI_JOB_TOKEN")
13 | }
14 |
15 | publishing {
16 | publications {
17 | library(MavenPublication) {
18 | from components.java
19 | }
20 | }
21 | repositories {
22 | maven { //
23 | url "https://gitlab.cc-asp.fraunhofer.de/api/v4/projects/36/packages/maven"
24 | name "GitLab"
25 | credentials(HttpHeaderCredentials) {
26 | name = tokenName
27 | value = tokenValue
28 | }
29 | authentication {
30 | header(HttpHeaderAuthentication)
31 | }
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gythialy/j60870/c4619c98cfbddecc1328c848f55504f89a27b029/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
6 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/license/LICENSE_HEADER.txt:
--------------------------------------------------------------------------------
1 | Copyright 2014-2023 Fraunhofer ISE
2 |
3 | This file is part of j60870.
4 | For more information visit http://www.openmuc.org
5 |
6 | j60870 is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | j60870 is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with j60870. If not, see .
18 |
--------------------------------------------------------------------------------
/run-scripts/j60870-console-client:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | JARS_LOCATION_APP="../cli-app/build/libs"
4 | JARS_LOCATION_LIB="../build/libs-all"
5 | MAIN_CLASS="org.openmuc.j60870.app.ConsoleClient"
6 | SYSPROPS=""
7 | PARAMS=""
8 |
9 | SCRIPT_HOME=`dirname $0`
10 |
11 | CLASSPATH_LIB=$(JARS=("$SCRIPT_HOME"/"$JARS_LOCATION_LIB"/*.jar); IFS=:; echo "${JARS[*]}")
12 | CLASSPATH_APP=$(JARS=("$SCRIPT_HOME"/"$JARS_LOCATION_APP"/*.jar); IFS=:; echo "${JARS[*]}")
13 |
14 | for i in $@; do
15 | if [[ $i == -D* ]]; then
16 | SYSPROPS="$SYSPROPS $i";
17 | else
18 | PARAMS="$PARAMS $i";
19 | fi
20 | done
21 |
22 | java $SYSPROPS -cp $CLASSPATH_LIB:$CLASSPATH_APP $MAIN_CLASS $PARAMS
23 |
--------------------------------------------------------------------------------
/run-scripts/j60870-console-client.bat:
--------------------------------------------------------------------------------
1 | ::BATCH file for windows
2 | @echo off
3 | set BATDIR=%~dp0
4 | set CLIDIR=%BATDIR%..\cli-app\build\libs\*
5 | set LIBDIR=%BATDIR%..\build\libs\*
6 | @echo on
7 |
8 | java -cp "%LIBDIR%;%CLIDIR%" org.openmuc.j60870.app.ConsoleClient %*
9 |
--------------------------------------------------------------------------------
/run-scripts/j60870-sample-server:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | JARS_LOCATION_APP="../cli-app/build/libs"
4 | JARS_LOCATION_LIB="../build/libs-all"
5 | MAIN_CLASS="org.openmuc.j60870.app.SampleServer"
6 | SYSPROPS=""
7 | PARAMS=""
8 |
9 | SCRIPT_HOME=`dirname $0`
10 |
11 | CLASSPATH_LIB=$(JARS=("$SCRIPT_HOME"/"$JARS_LOCATION_LIB"/*.jar); IFS=:; echo "${JARS[*]}")
12 | CLASSPATH_APP=$(JARS=("$SCRIPT_HOME"/"$JARS_LOCATION_APP"/*.jar); IFS=:; echo "${JARS[*]}")
13 |
14 | for i in $@; do
15 | if [[ $i == -D* ]]; then
16 | SYSPROPS="$SYSPROPS $i";
17 | else
18 | PARAMS="$PARAMS $i";
19 | fi
20 | done
21 |
22 | java $SYSPROPS -cp $CLASSPATH_LIB:$CLASSPATH_APP $MAIN_CLASS $PARAMS
23 |
--------------------------------------------------------------------------------
/run-scripts/j60870-sample-server.bat:
--------------------------------------------------------------------------------
1 | ::BATCH file for windows
2 | @echo off
3 | set BATDIR=%~dp0
4 | set CLIDIR=%BATDIR%..\cli-app\build\libs\*
5 | set LIBDIR=%BATDIR%..\build\libs\*
6 | @echo on
7 |
8 | java -cp "%LIBDIR%;%CLIDIR%" org.openmuc.j60870.app.SampleServer %*
9 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include "cli-app"
2 |
3 | project(":cli-app").projectDir = file("cli-app")
4 |
--------------------------------------------------------------------------------
/src/docs/asciidoc/common-settings.txt:
--------------------------------------------------------------------------------
1 | ifndef::imagesdir[:imagesdir: images]
2 | ifdef::backend-pdf[]
3 | Fraunhofer Institute for Solar Energy Systems ISE
4 | openmuc.org
5 | //:doctype: book
6 | // Settings:
7 | :compat-mode:
8 | :experimental:
9 | :icons: font
10 | :listing-caption: Listing
11 | :sectnums:
12 | :toc:
13 | :toclevels: 3
14 | :title-logo-image: image:banner.png[pdfwidth=90%,align=center]
15 | :frame: none
16 |
17 | :width100: 750
18 | :width80: 600
19 | :width60: 450
20 | :width40: 300
21 | :width20: 150
22 |
23 | endif::[]
24 |
25 | ifndef::backend-pdf[]
26 |
27 | :width100: "100%"
28 | :width80: "80%"
29 | :width60: "60%"
30 | :width40: "40%"
31 | :width20: "20%"
32 |
33 | endif::[]
34 |
--------------------------------------------------------------------------------
/src/docs/asciidoc/images/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gythialy/j60870/c4619c98cfbddecc1328c848f55504f89a27b029/src/docs/asciidoc/images/banner.png
--------------------------------------------------------------------------------
/src/docs/asciidoc/pdf-theme.yml:
--------------------------------------------------------------------------------
1 | title_page:
2 | align: right
3 |
4 | page:
5 | layout: portrait
6 | # margin: [0.75in, 1in, 0.75in, 1in]
7 | size: A4
8 |
9 | base:
10 | font_family: Times-Roman
11 | font_color: #333333
12 | font_size: 11
13 | line_height_length: 17
14 | line_height: $base_line_height_length / $base_font_size
15 |
16 | vertical_rhythm: $base_line_height_length
17 |
18 | heading:
19 | font_color: #0000
20 | font_size: 14
21 | font_style: bold
22 | line_height: 1.2
23 | margin_bottom: $vertical_rhythm
24 |
25 | link:
26 | font_color: #939393
27 |
28 | outline_list:
29 | indent: $base_font_size * 1.5
30 |
31 | header:
32 | height: 0.75in
33 | line_height: 1
34 | recto_content:
35 | center: '{document-title}'
36 | verso_content:
37 | center: '{document-title}'
38 |
39 | footer:
40 | height: 0.75in
41 | line_height: 1
42 | recto_content:
43 | right: '*{page-number}*'
44 | verso_content:
45 | left: '*{page-number}*'
46 |
47 | caption:
48 | align: left
49 | font_color: #000000
50 | font_size: 9
51 |
52 | code:
53 | border_color: #cccccc
54 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ConnectionEventListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import java.io.IOException;
24 | import java.util.EventListener;
25 |
26 | /**
27 | * The listener interface for receiving incoming ASDUs and connection closed events. The class that is interested in
28 | * incoming ASDUs implements this interface. The object of that class is registered as a listener through the
29 | * {@link ClientConnectionBuilder#setConnectionEventListener(ConnectionEventListener)} or returned by
30 | * {@link ServerEventListener#connectionIndication(Connection)}. Incoming ASDUs are queued so that
31 | * {@link #newASdu(Connection connection, ASdu)} is never called simultaneously for the same connection.
32 | */
33 | public interface ConnectionEventListener extends EventListener {
34 |
35 | /**
36 | * Invoked when a new ASDU arrives.
37 | *
38 | * @param aSdu the ASDU that arrived.
39 | */
40 | void newASdu(Connection connection, ASdu aSdu);
41 |
42 | /**
43 | * Invoked when an IOException occurred while listening for incoming ASDUs. An IOException implies that the
44 | * {@link Connection} that feeds this listener was automatically closed and can no longer be used to send commands
45 | * or receive ASDUs.
46 | *
47 | * @param cause the exception that occurred.
48 | */
49 | void connectionClosed(Connection connection, IOException cause);
50 |
51 | /**
52 | * Informs when the state of data transfer changed.
53 | *
54 | * @param stopped true if data transfer stopped, false if data transfer started
55 | */
56 | void dataTransferStateChanged(Connection connection, boolean stopped);
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ReservedASduTypeDecoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import org.openmuc.j60870.ie.InformationObject;
24 | import org.openmuc.j60870.internal.ExtendedDataInputStream;
25 |
26 | import java.util.List;
27 |
28 | public interface ReservedASduTypeDecoder {
29 | public List getSupportedTypes();
30 |
31 | public InformationObject decode(ExtendedDataInputStream is, ASduType aSduType);
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ServerEventListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import java.io.IOException;
24 | import java.util.EventListener;
25 |
26 | public interface ServerEventListener extends EventListener {
27 |
28 | ConnectionEventListener connectionIndication(Connection connection);
29 |
30 | /**
31 | * This function is only called when an IOException in ServerSocket.accept() occurred which was not forced using
32 | * ServerSap.stopListening()
33 | *
34 | * @param e The IOException caught form ServerSocket.accept()
35 | */
36 | void serverStoppedListeningIndication(IOException e);
37 |
38 | void connectionAttemptFailed(IOException e);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/TimeoutManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import java.util.concurrent.PriorityBlockingQueue;
24 |
25 | class TimeoutManager implements Runnable {
26 |
27 | private static final int INITIAL_QUE_CAPACITY = 4;
28 | private final PriorityBlockingQueue queue;
29 | private final Object guardedLock;
30 | boolean canceled;
31 |
32 | public TimeoutManager() {
33 | this.queue = new PriorityBlockingQueue<>(INITIAL_QUE_CAPACITY);
34 | this.guardedLock = new Object();
35 | }
36 |
37 | public void addTimerTask(TimeoutTask task) {
38 | task.updateDueTime();
39 | removeDuplicates(task);
40 | this.queue.add(task);
41 | notifyLock();
42 | }
43 |
44 | private void notifyLock() {
45 | synchronized (this.guardedLock) {
46 | this.guardedLock.notifyAll();
47 | }
48 | }
49 |
50 | private void removeDuplicates(TimeoutTask task) {
51 | while (queue.remove(task)) {
52 | // continue removing until there are no duplicates
53 | }
54 | }
55 |
56 | public void cancel() {
57 | this.canceled = true;
58 | }
59 |
60 | @Override
61 | public void run() {
62 | Thread.currentThread().setName("TimeoutManager");
63 | TimeoutTask currentTask;
64 | while (!canceled) {
65 | try {
66 | long sleepMillis;
67 | currentTask = queue.take();
68 |
69 | while ((sleepMillis = currentTask.sleepTimeFromDueTime()) > 0) {
70 | queue.put(currentTask);
71 |
72 | synchronized (this.guardedLock) {
73 | this.guardedLock.wait(sleepMillis);
74 | }
75 | currentTask = queue.take();
76 | }
77 |
78 | currentTask.executeManually();
79 | } catch (InterruptedException e) {
80 | // Restore interrupted state...
81 | Thread.currentThread().interrupt();
82 | return;
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/TimeoutTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | abstract class TimeoutTask implements Comparable {
24 | private final long timeout;
25 |
26 | private long dueTime;
27 |
28 | private boolean canceled;
29 | private boolean done;
30 |
31 | public TimeoutTask(long timeout) {
32 |
33 | this.timeout = timeout;
34 | this.done = false;
35 | this.canceled = false;
36 | this.dueTime = 0;
37 | }
38 |
39 | void executeManually() {
40 |
41 | if (canceled) {
42 | return;
43 | }
44 |
45 | try {
46 | execute();
47 | } finally {
48 | this.done = true;
49 | }
50 | }
51 |
52 | void updateDueTime() {
53 |
54 | this.dueTime = System.currentTimeMillis() + timeout;
55 | this.canceled = false;
56 | this.done = false;
57 | }
58 |
59 | protected abstract void execute();
60 |
61 | public boolean isPlanned() {
62 |
63 | return !this.canceled && !this.done && dueTime != 0;
64 | }
65 |
66 | public boolean isDone() {
67 |
68 | return done;
69 | }
70 |
71 | public void cancel() {
72 |
73 | this.canceled = true;
74 | }
75 |
76 | public long sleepTimeFromDueTime() {
77 |
78 | return dueTime - System.currentTimeMillis();
79 | }
80 |
81 | @Override
82 | public int compareTo(TimeoutTask o) {
83 |
84 | return Long.compare(this.dueTime, o.dueTime);
85 | }
86 |
87 | @Override
88 | public boolean equals(Object obj) {
89 |
90 | if (!(obj instanceof TimeoutTask)) {
91 | return false;
92 | }
93 |
94 | TimeoutTask o = (TimeoutTask) obj;
95 | return this.dueTime == o.dueTime && this.canceled == o.canceled && this.done == o.done
96 | && this.timeout == o.timeout;
97 | }
98 |
99 | @Override
100 | public int hashCode() {
101 |
102 | return Long.hashCode(this.timeout) ^ ((Boolean.valueOf(canceled).hashCode()) << 2)
103 | ^ Boolean.valueOf(done).hashCode();
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/UnknownAsduTypeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import java.io.IOException;
24 |
25 | class UnknownAsduTypeException extends IOException {
26 |
27 | private static final long serialVersionUID = -1780392504515716756L;
28 |
29 | public UnknownAsduTypeException() {
30 | super();
31 | }
32 |
33 | public UnknownAsduTypeException(String message) {
34 | super(message);
35 | }
36 |
37 | public UnknownAsduTypeException(String message, Throwable cause) {
38 | super(message, cause);
39 | }
40 |
41 | public UnknownAsduTypeException(Throwable cause) {
42 | super(cause);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | /**
24 | * Class offering static utility functions.
25 | */
26 | public class Util {
27 |
28 | private Util() {
29 | }
30 |
31 | /**
32 | * Returns the Information Object Address (IOA) calculated from the given bytes. The first byte is the least
33 | * significant byte of the IOA.
34 | *
35 | * @param byte1 the first byte
36 | * @param byte2 the second byte
37 | * @param byte3 the third byte
38 | * @return the IOA
39 | */
40 | public static int convertToInformationObjectAddress(int byte1, int byte2, int byte3) {
41 | return byte1 + (byte2 << 8) + (byte3 << 16);
42 | }
43 |
44 | /**
45 | * Returns the Common Address (CA) calculated from the given bytes. The first byte is the least significant byte of
46 | * the CA.
47 | *
48 | * @param byte1 the first byte
49 | * @param byte2 the second byte
50 | * @return the CA
51 | */
52 | public static int convertToCommonAddress(int byte1, int byte2) {
53 | return byte1 + (byte2 << 8);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeAbstractQualifierOfCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | abstract class IeAbstractQualifierOfCommand extends InformationElement {
27 |
28 | protected int value;
29 |
30 | IeAbstractQualifierOfCommand(int qualifier, boolean select) {
31 |
32 | if (qualifier < 0 || qualifier > 31) {
33 | throw new IllegalArgumentException("Qualifier is out of bound: " + qualifier);
34 | }
35 |
36 | value = qualifier << 2;
37 |
38 | if (select) {
39 | value |= 0x80;
40 | }
41 |
42 | }
43 |
44 | IeAbstractQualifierOfCommand(DataInputStream is) throws IOException {
45 | value = (is.readByte() & 0xff);
46 | }
47 |
48 | @Override
49 | int encode(byte[] buffer, int i) {
50 | buffer[i] = (byte) value;
51 | return 1;
52 | }
53 |
54 | /**
55 | * Returns true if the command selects and false if the command executes.
56 | *
57 | * @return true if the command selects and false if the command executes.
58 | */
59 | public boolean isSelect() {
60 | return (value & 0x80) == 0x80;
61 | }
62 |
63 | public int getQualifier() {
64 | return (value >> 2) & 0x1f;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "selected: " + isSelect() + ", qualifier: " + getQualifier();
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeAbstractQuality.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.text.MessageFormat;
26 |
27 | abstract class IeAbstractQuality extends InformationElement {
28 |
29 | protected int value;
30 |
31 | public IeAbstractQuality(boolean blocked, boolean substituted, boolean notTopical, boolean invalid) {
32 |
33 | value = 0;
34 |
35 | if (blocked) {
36 | value |= 0x10;
37 | }
38 | if (substituted) {
39 | value |= 0x20;
40 | }
41 | if (notTopical) {
42 | value |= 0x40;
43 | }
44 | if (invalid) {
45 | value |= 0x80;
46 | }
47 |
48 | }
49 |
50 | IeAbstractQuality(DataInputStream is) throws IOException {
51 | value = is.readUnsignedByte();
52 | }
53 |
54 | @Override
55 | int encode(byte[] buffer, int i) {
56 | buffer[i] = (byte) value;
57 | return 1;
58 | }
59 |
60 | public boolean isBlocked() {
61 | return hasBitSet(0x10);
62 | }
63 |
64 | public boolean isSubstituted() {
65 | return hasBitSet(0x20);
66 | }
67 |
68 | public boolean isNotTopical() {
69 | return hasBitSet(0x40);
70 | }
71 |
72 | public boolean isInvalid() {
73 | return hasBitSet(0x80);
74 | }
75 |
76 | private boolean hasBitSet(int mask) {
77 | return (value & mask) == mask;
78 | }
79 |
80 | @Override
81 | public String toString() {
82 | return MessageFormat.format("blocked: {0}, substituted: {1}, not topical: {2}, invalid: {3}", isBlocked(),
83 | isSubstituted(), isNotTopical(), isInvalid());
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeAckFileOrSectionQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents an acknowledge file or section qualifier (AFQ) information element.
28 | */
29 | public class IeAckFileOrSectionQualifier extends InformationElement {
30 |
31 | private final int action;
32 | private final int notice;
33 |
34 | public IeAckFileOrSectionQualifier(int action, int notice) {
35 | this.action = action;
36 | this.notice = notice;
37 | }
38 |
39 | static IeAckFileOrSectionQualifier decode(DataInputStream is) throws IOException {
40 |
41 | int b1 = is.readUnsignedByte();
42 | int action = b1 & 0x0f;
43 | int notice = (b1 >> 4) & 0x0f;
44 | return new IeAckFileOrSectionQualifier(action, notice);
45 | }
46 |
47 | @Override
48 | int encode(byte[] buffer, int i) {
49 | buffer[i] = (byte) (action | (notice << 4));
50 | return 1;
51 | }
52 |
53 | public int getRequest() {
54 | return action;
55 | }
56 |
57 | public int getFreeze() {
58 | return notice;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return String.format("Acknowledge file or section qualifier, action: %d, notice: %d.", action, notice);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeBinaryCounterReading.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import org.openmuc.j60870.internal.ExtendedDataInputStream;
24 |
25 | import java.io.IOException;
26 | import java.nio.ByteBuffer;
27 | import java.nio.ByteOrder;
28 | import java.util.EnumSet;
29 | import java.util.Iterator;
30 | import java.util.Set;
31 |
32 | /**
33 | * Represents a binary counter reading (BCR) information element.
34 | */
35 | public class IeBinaryCounterReading extends InformationElement {
36 |
37 | private final int counterReading;
38 | private final int sequenceNumber;
39 |
40 | private final Set flags;
41 |
42 | public IeBinaryCounterReading(int counterReading, int sequenceNumber, Set flags) {
43 | this.counterReading = counterReading;
44 | this.sequenceNumber = sequenceNumber;
45 | this.flags = flags;
46 | }
47 |
48 | public IeBinaryCounterReading(int counterReading, int sequenceNumber) {
49 | this(counterReading, sequenceNumber, EnumSet.noneOf(Flag.class));
50 | }
51 |
52 | public IeBinaryCounterReading(int counterReading, int sequenceNumber, Flag firstFlag, Flag... flag) {
53 | this(counterReading, sequenceNumber, EnumSet.of(firstFlag, flag));
54 | }
55 |
56 | static IeBinaryCounterReading decode(ExtendedDataInputStream is) throws IOException {
57 |
58 | int counterReading = is.readLittleEndianInt();
59 |
60 | byte b0 = is.readByte();
61 |
62 | int sequenceNumber = b0 & 0x1f;
63 |
64 | Set flags = Flag.flagsFor(b0);
65 | return new IeBinaryCounterReading(counterReading, sequenceNumber, flags);
66 |
67 | }
68 |
69 | @Override
70 | int encode(byte[] buffer, int i) {
71 |
72 | ByteBuffer buf = ByteBuffer.wrap(buffer, i, buffer.length - i);
73 | buf.order(ByteOrder.LITTLE_ENDIAN);
74 | buf.putInt(counterReading).put(seq());
75 |
76 | return buf.position() - i;
77 |
78 | }
79 |
80 | private byte seq() {
81 | byte v = (byte) sequenceNumber;
82 | for (Flag flag : flags) {
83 | v |= flag.mask;
84 | }
85 |
86 | return v;
87 | }
88 |
89 | public int getCounterReading() {
90 | return counterReading;
91 | }
92 |
93 | public int getSequenceNumber() {
94 | return sequenceNumber;
95 | }
96 |
97 | public Set getFlags() {
98 | return flags;
99 | }
100 |
101 | @Override
102 | public String toString() {
103 | return "Binary counter reading: " + counterReading + ", seq num: " + sequenceNumber + ", flags: " + flags;
104 | }
105 |
106 | public enum Flag {
107 | CARRY(0x20),
108 | COUNTER_ADJUSTED(0x40),
109 | INVALID(0x80);
110 |
111 | private int mask;
112 |
113 | private Flag(int mask) {
114 | this.mask = mask;
115 | }
116 |
117 | private static Set flagsFor(byte b) {
118 | EnumSet s = EnumSet.allOf(Flag.class);
119 |
120 | Iterator iter = s.iterator();
121 |
122 | while (iter.hasNext()) {
123 | int mask2 = iter.next().mask;
124 | if ((mask2 & b) != mask2) {
125 | iter.remove();
126 | }
127 | }
128 |
129 | return s;
130 | }
131 |
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeBinaryStateInformation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import org.openmuc.j60870.internal.HexUtils;
24 |
25 | import java.io.DataInputStream;
26 | import java.io.IOException;
27 |
28 | /**
29 | * Represents a binary state information (BSI) information element.
30 | */
31 | public class IeBinaryStateInformation extends InformationElement {
32 |
33 | private final int value;
34 |
35 | /**
36 | * Creates a BSI (binary state information) information element from an integer value.
37 | *
38 | * @param value the bits of value represent the 32 binary states of this element. When encoded in a message, the MSB
39 | * of value is transmitted first and the LSB of value is transmitted last.
40 | */
41 | public IeBinaryStateInformation(int value) {
42 | this.value = value;
43 | }
44 |
45 | /**
46 | * Creates a BSI (binary state information) information element from a byte array.
47 | *
48 | * @param value the bits of value represent the 32 binary states of this element. When encoded in a message, the MSB
49 | * of the first byte is transmitted first and the LSB of fourth byte is transmitted last.
50 | */
51 | public IeBinaryStateInformation(byte[] value) {
52 | if (value == null || value.length != 4) {
53 | throw new IllegalArgumentException("value needs to be of length 4");
54 | }
55 | this.value = (value[0] << 24) | ((value[1] & 0xff) << 16) | ((value[2] & 0xff) << 8) | (value[3] & 0xff);
56 | }
57 |
58 | IeBinaryStateInformation(DataInputStream is) throws IOException {
59 | value = is.readInt();
60 | }
61 |
62 | @Override
63 | int encode(byte[] buffer, int i) {
64 | buffer[i++] = (byte) (value >> 24);
65 | buffer[i++] = (byte) (value >> 16);
66 | buffer[i++] = (byte) (value >> 8);
67 | buffer[i] = (byte) value;
68 | return 4;
69 | }
70 |
71 | /**
72 | * Returns the 32 binary states of this element as an integer. When encoded in a message, the MSB of the return
73 | * value is transmitted first and the LSB of the return value is transmitted last.
74 | *
75 | * @return the 32 binary states of this element.
76 | */
77 | public int getValue() {
78 | return value;
79 | }
80 |
81 | /**
82 | * Returns the 32 binary states of this element as a byte array. When encoded in a message, the MSB of the first
83 | * byte is transmitted first and the LSB of the fourth byte is transmitted last.
84 | *
85 | * @return the 32 binary states of this element.
86 | */
87 | public byte[] getValueAsByteArray() {
88 | return new byte[]{(byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8), (byte) (value)};
89 | }
90 |
91 | /**
92 | * Returns true if the bit at the given position is 1 and false otherwise.
93 | *
94 | * @param position the position in the bit string. Range: 1-32. Position 1 represents the last bit in the encoded message
95 | * and is the least significant bit (LSB) of the value returned by getValue(). Position 32
96 | * represents the first bit in the encoded message and is the most significant bit (MSB) of the value
97 | * returned by getValue().
98 | * @return true if the bit at the given position is 1 and false otherwise.
99 | */
100 | public boolean getBinaryState(int position) {
101 | if (position < 1 || position > 32) {
102 | throw new IllegalArgumentException("Position out of bound. Should be between 1 and 32.");
103 | }
104 | return (((value >> (position - 1)) & 0x01) == 0x01);
105 | }
106 |
107 | @Override
108 | public String toString() {
109 | return "BinaryStateInformation (32 bits as hex): " + HexUtils.bytesToHex(
110 | new byte[]{(byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8), (byte) (value)});
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeCauseOfInitialization.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a cause of initialization (COI) information element.
28 | */
29 | public class IeCauseOfInitialization extends InformationElement {
30 |
31 | private final int value;
32 | private final boolean initAfterParameterChange;
33 |
34 | /**
35 | * Creates a COI (cause of initialization) information element.
36 | *
37 | * @param value value between 0 and 127
38 | * @param initAfterParameterChange true if initialization after change of local parameters and false if initialization with unchanged
39 | * local parameters
40 | */
41 | public IeCauseOfInitialization(int value, boolean initAfterParameterChange) {
42 |
43 | if (value < 0 || value > 127) {
44 | throw new IllegalArgumentException("Value has to be in the range 0..127");
45 | }
46 |
47 | this.value = value;
48 | this.initAfterParameterChange = initAfterParameterChange;
49 |
50 | }
51 |
52 | IeCauseOfInitialization(DataInputStream is) throws IOException {
53 | int b1 = (is.readByte() & 0xff);
54 |
55 | initAfterParameterChange = ((b1 & 0x80) == 0x80);
56 |
57 | value = b1 & 0x7f;
58 |
59 | }
60 |
61 | @Override
62 | int encode(byte[] buffer, int i) {
63 |
64 | if (initAfterParameterChange) {
65 | buffer[i] = (byte) (value | 0x80);
66 | } else {
67 | buffer[i] = (byte) value;
68 | }
69 |
70 | return 1;
71 |
72 | }
73 |
74 | public int getValue() {
75 | return value;
76 | }
77 |
78 | public boolean isInitAfterParameterChange() {
79 | return initAfterParameterChange;
80 | }
81 |
82 | @Override
83 | public String toString() {
84 | return "Cause of initialization: " + value + ", init after parameter change: " + initAfterParameterChange;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeChecksum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a checksum (CHS) information element.
28 | */
29 | public class IeChecksum extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeChecksum(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeChecksum decode(DataInputStream is) throws IOException {
38 | return new IeChecksum(is.readUnsignedByte());
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 | }
46 |
47 | public int getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Checksum: " + value;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeDoubleCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.util.HashMap;
26 | import java.util.Map;
27 |
28 | /**
29 | * Represents a double command (DCO) information element.
30 | */
31 | public class IeDoubleCommand extends IeAbstractQualifierOfCommand {
32 |
33 | /**
34 | * Create the Double Command Information Element.
35 | *
36 | * @param commandState the command state
37 | * @param qualifier the qualifier
38 | * @param select true if select, false if execute
39 | */
40 | public IeDoubleCommand(DoubleCommandState commandState, int qualifier, boolean select) {
41 | super(qualifier, select);
42 |
43 | value |= commandState.getId();
44 | }
45 |
46 | IeDoubleCommand(DataInputStream is) throws IOException {
47 | super(is);
48 | }
49 |
50 | public DoubleCommandState getCommandState() {
51 | return DoubleCommandState.getInstance(value & 0x03);
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Double Command state: " + getCommandState() + ", " + super.toString();
57 | }
58 |
59 | public enum DoubleCommandState {
60 | NOT_PERMITTED_A(0),
61 | OFF(1),
62 | ON(2),
63 | NOT_PERMITTED_B(3);
64 |
65 | private static final Map idMap = new HashMap<>();
66 |
67 | static {
68 | for (DoubleCommandState enumInstance : DoubleCommandState.values()) {
69 | if (idMap.put(enumInstance.getId(), enumInstance) != null) {
70 | throw new IllegalArgumentException("duplicate ID: " + enumInstance.getId());
71 | }
72 | }
73 | }
74 |
75 | private final int id;
76 |
77 | private DoubleCommandState(int id) {
78 | this.id = id;
79 | }
80 |
81 | /**
82 | * Returns the DoubleCommandState that corresponds to the given ID. Returns null if no
83 | * DoubleCommandState with the given ID exists.
84 | *
85 | * @param id the ID
86 | * @return the DoubleCommandState that corresponds to the given ID
87 | */
88 | public static DoubleCommandState getInstance(int id) {
89 | return idMap.get(id);
90 | }
91 |
92 | /**
93 | * Returns the ID of this DoubleCommandState.
94 | *
95 | * @return the ID
96 | */
97 | public int getId() {
98 | return id;
99 | }
100 |
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeDoublePointWithQuality.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a double-point information with quality descriptor (DIQ) information element.
28 | */
29 | public class IeDoublePointWithQuality extends IeAbstractQuality {
30 |
31 | public IeDoublePointWithQuality(DoublePointInformation dpi, boolean blocked, boolean substituted,
32 | boolean notTopical, boolean invalid) {
33 | super(blocked, substituted, notTopical, invalid);
34 |
35 | switch (dpi) {
36 | case INDETERMINATE_OR_INTERMEDIATE:
37 | break;
38 | case OFF:
39 | value |= 0x01;
40 | break;
41 | case ON:
42 | value |= 0x02;
43 | break;
44 | case INDETERMINATE:
45 | value |= 0x03;
46 | break;
47 | }
48 | }
49 |
50 | IeDoublePointWithQuality(DataInputStream is) throws IOException {
51 | super(is);
52 | }
53 |
54 | public DoublePointInformation getDoublePointInformation() {
55 | switch (value & 0x03) {
56 | case 0:
57 | return DoublePointInformation.INDETERMINATE_OR_INTERMEDIATE;
58 | case 1:
59 | return DoublePointInformation.OFF;
60 | case 2:
61 | return DoublePointInformation.ON;
62 | default:
63 | return DoublePointInformation.INDETERMINATE;
64 | }
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "Double Point: " + getDoublePointInformation() + ", " + super.toString();
70 | }
71 |
72 | public enum DoublePointInformation {
73 | INDETERMINATE_OR_INTERMEDIATE,
74 | OFF,
75 | ON,
76 | INDETERMINATE;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeFileReadyQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a file ready qualifier (FRQ) information element.
28 | */
29 | public class IeFileReadyQualifier extends InformationElement {
30 |
31 | private final int value;
32 | private final boolean negativeConfirm;
33 |
34 | public IeFileReadyQualifier(int value, boolean negativeConfirm) {
35 | this.value = value;
36 | this.negativeConfirm = negativeConfirm;
37 | }
38 |
39 | static InformationElement decode(DataInputStream is) throws IOException {
40 | int b1 = is.readUnsignedByte();
41 | int value = b1 & 0x7f;
42 | boolean negativeConfirm = ((b1 & 0x80) == 0x80);
43 |
44 | return new IeFileReadyQualifier(value, negativeConfirm);
45 | }
46 |
47 | @Override
48 | int encode(byte[] buffer, int i) {
49 | buffer[i] = (byte) value;
50 | if (negativeConfirm) {
51 | buffer[i] |= 0x80;
52 | }
53 | return 1;
54 | }
55 |
56 | public int getValue() {
57 | return value;
58 | }
59 |
60 | public boolean isNegativeConfirm() {
61 | return negativeConfirm;
62 | }
63 |
64 | @Override
65 | public String toString() {
66 | return "File ready qualifier: " + value + ", negative confirm: " + negativeConfirm;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeFileSegment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents the segment of a file as transferred by ASDUs of type F_SG_NA_1 (125).
28 | */
29 | public class IeFileSegment extends InformationElement {
30 |
31 | private final byte[] segment;
32 | private final int offset;
33 | private final int length;
34 |
35 | public IeFileSegment(byte[] segment, int offset, int length) {
36 | this.segment = segment;
37 | this.offset = offset;
38 | this.length = length;
39 | }
40 |
41 | IeFileSegment(DataInputStream is) throws IOException {
42 |
43 | length = (is.readByte() & 0xff);
44 | segment = new byte[length];
45 |
46 | is.readFully(segment);
47 | offset = 0;
48 | }
49 |
50 | @Override
51 | int encode(byte[] buffer, int i) {
52 |
53 | buffer[i++] = (byte) length;
54 |
55 | System.arraycopy(segment, offset, buffer, i, length);
56 |
57 | return length + 1;
58 |
59 | }
60 |
61 | public byte[] getSegment() {
62 | return segment;
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "File segment of length: " + length;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeFixedTestBitPattern.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a fixed test bit pattern (FBP) information element.
28 | */
29 | public class IeFixedTestBitPattern extends InformationElement {
30 |
31 | public IeFixedTestBitPattern() {
32 | }
33 |
34 | IeFixedTestBitPattern(DataInputStream is) throws IOException {
35 | if ((is.readByte() & 0xff) != 0x55 || (is.readByte() & 0xff) != 0xaa) {
36 | throw new IOException("Incorrect bit pattern in Fixed Test Bit Pattern.");
37 | }
38 | }
39 |
40 | @Override
41 | int encode(byte[] buffer, int i) {
42 |
43 | buffer[i++] = 0x55;
44 | buffer[i] = (byte) 0xaa;
45 | return 2;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "Fixed test bit pattern";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeLastSectionOrSegmentQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a last section or segment qualifier (LSQ) information element.
28 | */
29 | public class IeLastSectionOrSegmentQualifier extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeLastSectionOrSegmentQualifier(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeLastSectionOrSegmentQualifier decode(DataInputStream is) throws IOException {
38 | return new IeLastSectionOrSegmentQualifier(is.readUnsignedByte());
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 | }
46 |
47 | public int getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Last section or segment qualifier: " + value;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeLengthOfFileOrSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a length of file or section (LOF) information element.
28 | */
29 | public class IeLengthOfFileOrSection extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeLengthOfFileOrSection(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeLengthOfFileOrSection decode(DataInputStream is) throws IOException {
38 | int value = 0;
39 | for (int i = 0; i < 3; ++i) {
40 | value |= is.readUnsignedByte() << (i * 8);
41 | }
42 | return new IeLengthOfFileOrSection(value);
43 | }
44 |
45 | @Override
46 | int encode(byte[] buffer, int i) {
47 |
48 | buffer[i++] = (byte) value;
49 | buffer[i++] = (byte) (value >> 8);
50 | buffer[i] = (byte) (value >> 16);
51 |
52 | return 3;
53 |
54 | }
55 |
56 | public int getValue() {
57 | return value;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "Length of file or section: " + value;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeNameOfFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a name of file (NOF) information element.
28 | */
29 | public class IeNameOfFile extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeNameOfFile(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeNameOfFile decode(DataInputStream is) throws IOException {
38 | int value = is.readUnsignedByte() | (is.readUnsignedByte() << 8);
39 | return new IeNameOfFile(value);
40 | }
41 |
42 | @Override
43 | int encode(byte[] buffer, int i) {
44 | buffer[i++] = (byte) value;
45 | buffer[i] = (byte) (value >> 8);
46 |
47 | return 2;
48 |
49 | }
50 |
51 | public int getValue() {
52 | return value;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "Name of file: " + value;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeNameOfSection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a name of section (NOS) information element.
28 | */
29 | public class IeNameOfSection extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeNameOfSection(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeNameOfSection decode(DataInputStream is) throws IOException {
38 | return new IeNameOfSection(is.readUnsignedByte());
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 |
46 | }
47 |
48 | public int getValue() {
49 | return value;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "Name of section: " + value;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeNormalizedValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a normalized value (NVA) information element.
28 | */
29 | public class IeNormalizedValue extends InformationElement {
30 |
31 | final int value;
32 |
33 | /**
34 | * Normalized value is a value in the range from -1 to (1-1/(2^15)). The normalized value is encoded as a 16 bit
35 | * integer ranging from -32768 to 32767. In order to get the normalized value the integer value is divided by 32768.
36 | * Use this constructor to initialize the value exactly using the integer value in the range from -32768 to 32767.
37 | *
38 | * @param value non-normalized value in the range -32768 to 32767
39 | */
40 | public IeNormalizedValue(int value) {
41 | if (value < -32768 || value > 32767) {
42 | throw new IllegalArgumentException("Value has to be in the range -32768..32767");
43 | }
44 | this.value = value;
45 | }
46 |
47 | /**
48 | * Normalized value is a value in the range from -1 to (1-1/(2^15)). Use this constructor to initialize the value
49 | * using a double value ranging from -1 to (1-1/(2^15)).
50 | *
51 | * @param value normalized value in the range -1 to (1-1/(2^15))
52 | */
53 | public IeNormalizedValue(double value) {
54 | this.value = (int) (value * 32768.0);
55 | if (this.value < -32768 || this.value > 32767) {
56 | throw new IllegalArgumentException(
57 | "The value multiplied by 32768 has to be an integer in the range -32768..32767, but it is: "
58 | + this.value);
59 | }
60 | }
61 |
62 | IeNormalizedValue(DataInputStream is) throws IOException {
63 | value = (is.readByte() & 0xff) | (is.readByte() << 8);
64 | }
65 |
66 | @Override
67 | int encode(byte[] buffer, int i) {
68 |
69 | buffer[i++] = (byte) value;
70 | buffer[i] = (byte) (value >> 8);
71 |
72 | return 2;
73 | }
74 |
75 | /**
76 | * Get the value as a normalized double value ranging from -1 to (1-1/(2^15))
77 | *
78 | * @return the value as a normalized double.
79 | */
80 | public double getNormalizedValue() {
81 | return ((double) value) / 32768;
82 | }
83 |
84 | /**
85 | * Get the value as a non-normalized integer value ranging from -32768..32767. In order to get the normalized value
86 | * the returned integer value has to be devided by 32768. The normalized value can also be retrieved using
87 | * {@link #getNormalizedValue()}
88 | *
89 | * @return the value as a non-normalized integer value
90 | */
91 | public int getUnnormalizedValue() {
92 | return value;
93 | }
94 |
95 | @Override
96 | public String toString() {
97 | return "Normalized value: " + ((double) value / 32768);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeProtectionOutputCircuitInformation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents an output circuit information of protection equipment (OCI) information element.
28 | */
29 | public class IeProtectionOutputCircuitInformation extends InformationElement {
30 |
31 | private int value;
32 |
33 | public IeProtectionOutputCircuitInformation(boolean generalCommand, boolean commandToL1, boolean commandToL2,
34 | boolean commandToL3) {
35 |
36 | value = 0;
37 |
38 | if (generalCommand) {
39 | value |= 0x01;
40 | }
41 | if (commandToL1) {
42 | value |= 0x02;
43 | }
44 | if (commandToL2) {
45 | value |= 0x04;
46 | }
47 | if (commandToL3) {
48 | value |= 0x08;
49 | }
50 |
51 | }
52 |
53 | IeProtectionOutputCircuitInformation(DataInputStream is) throws IOException {
54 | value = (is.readByte() & 0xff);
55 | }
56 |
57 | @Override
58 | int encode(byte[] buffer, int i) {
59 | buffer[i] = (byte) value;
60 | return 1;
61 | }
62 |
63 | public boolean isGeneralCommand() {
64 | return (value & 0x01) == 0x01;
65 | }
66 |
67 | public boolean isCommandToL1() {
68 | return (value & 0x02) == 0x02;
69 | }
70 |
71 | public boolean isCommandToL2() {
72 | return (value & 0x04) == 0x04;
73 | }
74 |
75 | public boolean isCommandToL3() {
76 | return (value & 0x08) == 0x08;
77 | }
78 |
79 | @Override
80 | public String toString() {
81 | return "Protection output circuit information, general command: " + isGeneralCommand() + ", command to L1: "
82 | + isCommandToL1() + ", command to L2: " + isCommandToL2() + ", command to L3: " + isCommandToL3();
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeProtectionQuality.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a quality descriptor for events of protection equipment (QDP) information element.
28 | */
29 | public class IeProtectionQuality extends IeAbstractQuality {
30 |
31 | public IeProtectionQuality(boolean elapsedTimeInvalid, boolean blocked, boolean substituted, boolean notTopical,
32 | boolean invalid) {
33 | super(blocked, substituted, notTopical, invalid);
34 |
35 | if (elapsedTimeInvalid) {
36 | value |= 0x08;
37 | }
38 | }
39 |
40 | IeProtectionQuality(DataInputStream is) throws IOException {
41 | super(is);
42 | }
43 |
44 | public boolean isElapsedTimeInvalid() {
45 | return (value & 0x08) == 0x08;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "Protection Quality, elapsed time invalid: " + isElapsedTimeInvalid() + ", " + super.toString();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeProtectionStartEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a start events of protection equipment (SPE) information element.
28 | */
29 | public class IeProtectionStartEvent extends InformationElement {
30 |
31 | private int value;
32 |
33 | public IeProtectionStartEvent(boolean generalStart, boolean startOperationL1, boolean startOperationL2,
34 | boolean startOperationL3, boolean startOperationIe, boolean startReverseOperation) {
35 |
36 | value = 0;
37 |
38 | if (generalStart) {
39 | value |= 0x01;
40 | }
41 | if (startOperationL1) {
42 | value |= 0x02;
43 | }
44 | if (startOperationL2) {
45 | value |= 0x04;
46 | }
47 | if (startOperationL3) {
48 | value |= 0x08;
49 | }
50 | if (startOperationIe) {
51 | value |= 0x10;
52 | }
53 | if (startReverseOperation) {
54 | value |= 0x20;
55 | }
56 | }
57 |
58 | IeProtectionStartEvent(DataInputStream is) throws IOException {
59 | value = (is.readByte() & 0xff);
60 | }
61 |
62 | @Override
63 | int encode(byte[] buffer, int i) {
64 | buffer[i] = (byte) value;
65 | return 1;
66 | }
67 |
68 | public boolean isGeneralStart() {
69 | return (value & 0x01) == 0x01;
70 | }
71 |
72 | public boolean isStartOperationL1() {
73 | return (value & 0x02) == 0x02;
74 | }
75 |
76 | public boolean isStartOperationL2() {
77 | return (value & 0x04) == 0x04;
78 | }
79 |
80 | public boolean isStartOperationL3() {
81 | return (value & 0x08) == 0x08;
82 | }
83 |
84 | public boolean isStartOperationIe() {
85 | return (value & 0x10) == 0x10;
86 | }
87 |
88 | public boolean isStartReverseOperation() {
89 | return (value & 0x20) == 0x20;
90 | }
91 |
92 | @Override
93 | public String toString() {
94 | return "Protection start event, general start of operation: " + isGeneralStart() + ", start of operation L1: "
95 | + isStartOperationL1() + ", start of operation L2: " + isStartOperationL2()
96 | + ", start of operation L3: " + isStartOperationL3() + ", start of operation IE(earth current): "
97 | + isStartOperationIe() + ", start of operation in reverse direction: " + isStartReverseOperation();
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfCounterInterrogation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of counter interrogation (QCC) information element.
28 | */
29 | public class IeQualifierOfCounterInterrogation extends InformationElement {
30 |
31 | private final int request;
32 | private final int freeze;
33 |
34 | public IeQualifierOfCounterInterrogation(int request, int freeze) {
35 | this.request = request;
36 | this.freeze = freeze;
37 | }
38 |
39 | IeQualifierOfCounterInterrogation(DataInputStream is) throws IOException {
40 | int b1 = (is.readByte() & 0xff);
41 | request = b1 & 0x3f;
42 | freeze = (b1 >> 6) & 0x03;
43 | }
44 |
45 | @Override
46 | int encode(byte[] buffer, int i) {
47 | buffer[i] = (byte) (request | (freeze << 6));
48 | return 1;
49 | }
50 |
51 | public int getRequest() {
52 | return request;
53 | }
54 |
55 | public int getFreeze() {
56 | return freeze;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | return "Qualifier of counter interrogation, request: " + request + ", freeze: " + freeze;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfInterrogation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of interrogation (QOI) information element.
28 | */
29 | public class IeQualifierOfInterrogation extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeQualifierOfInterrogation(int value) {
34 | this.value = value;
35 | }
36 |
37 | IeQualifierOfInterrogation(DataInputStream is) throws IOException {
38 | value = (is.readByte() & 0xff);
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 | }
46 |
47 | public int getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Qualifier of interrogation: " + value;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfParameterActivation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of parameter activation (QPA) information element.
28 | */
29 | public class IeQualifierOfParameterActivation extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeQualifierOfParameterActivation(int value) {
34 | this.value = value;
35 | }
36 |
37 | static IeQualifierOfParameterActivation decode(DataInputStream is) throws IOException {
38 | return new IeQualifierOfParameterActivation(is.readUnsignedByte());
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 | }
46 |
47 | public int getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Qualifier of parameter activation: " + value;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfParameterOfMeasuredValues.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of parameter of measured values (QPM) information element.
28 | */
29 | public class IeQualifierOfParameterOfMeasuredValues extends InformationElement {
30 |
31 | private final int kindOfParameter;
32 | private final boolean change;
33 | private final boolean notInOperation;
34 |
35 | public IeQualifierOfParameterOfMeasuredValues(int kindOfParameter, boolean change, boolean notInOperation) {
36 | this.kindOfParameter = kindOfParameter;
37 | this.change = change;
38 | this.notInOperation = notInOperation;
39 | }
40 |
41 | IeQualifierOfParameterOfMeasuredValues(DataInputStream is) throws IOException {
42 | int b1 = (is.readByte() & 0xff);
43 | kindOfParameter = b1 & 0x3f;
44 | change = ((b1 & 0x40) == 0x40);
45 | notInOperation = ((b1 & 0x80) == 0x80);
46 | }
47 |
48 | @Override
49 | int encode(byte[] buffer, int i) {
50 | buffer[i] = (byte) kindOfParameter;
51 | if (change) {
52 | buffer[i] |= 0x40;
53 | }
54 | if (notInOperation) {
55 | buffer[i] |= 0x80;
56 | }
57 | return 1;
58 | }
59 |
60 | public int getKindOfParameter() {
61 | return kindOfParameter;
62 | }
63 |
64 | public boolean isChange() {
65 | return change;
66 | }
67 |
68 | public boolean isNotInOperation() {
69 | return notInOperation;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return "Qualifier of parameter of measured values, kind of parameter: " + kindOfParameter + ", change: "
75 | + change + ", not in operation: " + notInOperation;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfResetProcessCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of reset process command (QRP) information element.
28 | */
29 | public class IeQualifierOfResetProcessCommand extends InformationElement {
30 |
31 | private final int value;
32 |
33 | public IeQualifierOfResetProcessCommand(int value) {
34 | this.value = value;
35 | }
36 |
37 | IeQualifierOfResetProcessCommand(DataInputStream is) throws IOException {
38 | value = (is.readByte() & 0xff);
39 | }
40 |
41 | @Override
42 | int encode(byte[] buffer, int i) {
43 | buffer[i] = (byte) value;
44 | return 1;
45 | }
46 |
47 | public int getValue() {
48 | return value;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "Qualifier of reset process command: " + value;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQualifierOfSetPointCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a qualifier of set-point command (QOS) information element.
28 | */
29 | public class IeQualifierOfSetPointCommand extends InformationElement {
30 |
31 | private final int ql;
32 | private final boolean select;
33 |
34 | public IeQualifierOfSetPointCommand(int ql, boolean select) {
35 | this.ql = ql;
36 | this.select = select;
37 | }
38 |
39 | IeQualifierOfSetPointCommand(DataInputStream is) throws IOException {
40 | int b1 = (is.readByte() & 0xff);
41 | ql = b1 & 0x7f;
42 | select = ((b1 & 0x80) == 0x80);
43 | }
44 |
45 | @Override
46 | int encode(byte[] buffer, int i) {
47 | buffer[i] = (byte) ql;
48 | if (select) {
49 | buffer[i] |= 0x80;
50 | }
51 | return 1;
52 | }
53 |
54 | public int getQl() {
55 | return ql;
56 | }
57 |
58 | public boolean isSelect() {
59 | return select;
60 | }
61 |
62 | @Override
63 | public String toString() {
64 | return "Qualifier of set point command, QL: " + ql + ", select: " + select;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeQuality.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a quality descriptor (QDS) information element.
28 | */
29 | public class IeQuality extends IeAbstractQuality {
30 |
31 | public IeQuality(boolean overflow, boolean blocked, boolean substituted, boolean notTopical, boolean invalid) {
32 | super(blocked, substituted, notTopical, invalid);
33 |
34 | if (overflow) {
35 | value |= 0x01;
36 | }
37 | }
38 |
39 | IeQuality(DataInputStream is) throws IOException {
40 | super(is);
41 | }
42 |
43 | public boolean isOverflow() {
44 | return (value & 0x01) == 0x01;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Quality, overflow: " + isOverflow() + ", " + super.toString();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeRegulatingStepCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.util.HashMap;
26 | import java.util.Map;
27 |
28 | /**
29 | * Represents a regulating step command (RCO) information element.
30 | */
31 | public class IeRegulatingStepCommand extends IeAbstractQualifierOfCommand {
32 |
33 | /**
34 | * Create a Regulating Step Command Information Element.
35 | *
36 | * @param commandState the command state
37 | * @param qualifier the qualifier
38 | * @param select true if select, false if execute
39 | */
40 | public IeRegulatingStepCommand(StepCommandState commandState, int qualifier, boolean select) {
41 | super(qualifier, select);
42 |
43 | value |= commandState.getId();
44 | }
45 |
46 | IeRegulatingStepCommand(DataInputStream is) throws IOException {
47 | super(is);
48 | }
49 |
50 | public StepCommandState getCommandState() {
51 | return StepCommandState.getInstance(value & 0x03);
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Regulating step command state: " + getCommandState() + ", " + super.toString();
57 | }
58 |
59 | public enum StepCommandState {
60 | NOT_PERMITTED_A(0),
61 | NEXT_STEP_LOWER(1),
62 | NEXT_STEP_HIGHER(2),
63 | NOT_PERMITTED_B(3);
64 |
65 | private static final Map idMap = new HashMap<>();
66 |
67 | static {
68 | for (StepCommandState enumInstance : StepCommandState.values()) {
69 | if (idMap.put(enumInstance.getId(), enumInstance) != null) {
70 | throw new IllegalArgumentException("duplicate ID: " + enumInstance.getId());
71 | }
72 | }
73 | }
74 |
75 | private final int id;
76 |
77 | private StepCommandState(int id) {
78 | this.id = id;
79 | }
80 |
81 | /**
82 | * Returns the StepCommandState that corresponds to the given ID. Returns null if no
83 | * StepCommandState with the given ID exists.
84 | *
85 | * @param id the ID
86 | * @return the StepCommandState that corresponds to the given ID
87 | */
88 | public static StepCommandState getInstance(int id) {
89 | return idMap.get(id);
90 | }
91 |
92 | /**
93 | * Returns the ID of this StepCommandState.
94 | *
95 | * @return the ID
96 | */
97 | public int getId() {
98 | return id;
99 | }
100 |
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeScaledValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a scaled value (SVA) information element.
28 | */
29 | public class IeScaledValue extends IeNormalizedValue {
30 |
31 | /**
32 | * Scaled value is a 16 bit integer (short) in the range from -32768 to 32767
33 | *
34 | * @param value value in the range -32768 to 32767
35 | */
36 | public IeScaledValue(int value) {
37 | super(value);
38 | }
39 |
40 | IeScaledValue(DataInputStream is) throws IOException {
41 | super(is);
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "Scaled value: " + value;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeSectionReadyQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a section ready qualifier (SRQ) information element.
28 | */
29 | public class IeSectionReadyQualifier extends InformationElement {
30 |
31 | private final int value;
32 | private final boolean sectionNotReady;
33 |
34 | public IeSectionReadyQualifier(int value, boolean sectionNotReady) {
35 | this.value = value;
36 | this.sectionNotReady = sectionNotReady;
37 | }
38 |
39 | static IeSectionReadyQualifier decode(DataInputStream is) throws IOException {
40 | int b1 = is.readUnsignedByte();
41 | int value = b1 & 0x7f;
42 | boolean sectionNotReady = ((b1 & 0x80) == 0x80);
43 | return new IeSectionReadyQualifier(value, sectionNotReady);
44 | }
45 |
46 | @Override
47 | int encode(byte[] buffer, int i) {
48 | buffer[i] = (byte) value;
49 | if (sectionNotReady) {
50 | buffer[i] |= 0x80;
51 | }
52 | return 1;
53 | }
54 |
55 | public int getValue() {
56 | return value;
57 | }
58 |
59 | public boolean isSectionNotReady() {
60 | return sectionNotReady;
61 | }
62 |
63 | @Override
64 | public String toString() {
65 | return "Section ready qualifier: " + value + ", section not ready: " + sectionNotReady;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeSelectAndCallQualifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a select and call qualifier (SCQ) information element.
28 | */
29 | public class IeSelectAndCallQualifier extends InformationElement {
30 |
31 | private final int action;
32 | private final int notice;
33 |
34 | public IeSelectAndCallQualifier(int action, int notice) {
35 | this.action = action;
36 | this.notice = notice;
37 | }
38 |
39 | static IeSelectAndCallQualifier decode(DataInputStream is) throws IOException {
40 | int b1 = is.readUnsignedByte();
41 |
42 | int action = b1 & 0x0f;
43 | int notice = (b1 >> 4) & 0x0f;
44 | return new IeSelectAndCallQualifier(action, notice);
45 | }
46 |
47 | @Override
48 | int encode(byte[] buffer, int i) {
49 | buffer[i] = (byte) (action | (notice << 4));
50 | return 1;
51 | }
52 |
53 | public int getRequest() {
54 | return action;
55 | }
56 |
57 | public int getFreeze() {
58 | return notice;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "Select and call qualifier, action: " + action + ", notice: " + notice;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeShortFloat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a short floating point number (R32-IEEE STD 754) information element.
28 | */
29 | public class IeShortFloat extends InformationElement {
30 |
31 | private final float value;
32 |
33 | public IeShortFloat(float value) {
34 | this.value = value;
35 | }
36 |
37 | IeShortFloat(DataInputStream is) throws IOException {
38 | value = Float.intBitsToFloat((is.readByte() & 0xff) | ((is.readByte() & 0xff) << 8)
39 | | ((is.readByte() & 0xff) << 16) | ((is.readByte() & 0xff) << 24));
40 | }
41 |
42 | @Override
43 | int encode(byte[] buffer, int i) {
44 |
45 | int tempVal = Float.floatToIntBits(value);
46 | buffer[i++] = (byte) tempVal;
47 | buffer[i++] = (byte) (tempVal >> 8);
48 | buffer[i++] = (byte) (tempVal >> 16);
49 | buffer[i] = (byte) (tempVal >> 24);
50 |
51 | return 4;
52 | }
53 |
54 | public float getValue() {
55 | return value;
56 | }
57 |
58 | @Override
59 | public String toString() {
60 | return "Short float value: " + value;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeSingleCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a single command (SCO) information element.
28 | */
29 | public class IeSingleCommand extends IeAbstractQualifierOfCommand {
30 |
31 | public IeSingleCommand(boolean commandStateOn, int qualifier, boolean select) {
32 | super(qualifier, select);
33 |
34 | if (commandStateOn) {
35 | value |= 0x01;
36 | }
37 | }
38 |
39 | IeSingleCommand(DataInputStream is) throws IOException {
40 | super(is);
41 | }
42 |
43 | public boolean isCommandStateOn() {
44 | return (value & 0x01) == 0x01;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Single Command state on: " + isCommandStateOn() + ", " + super.toString();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeSinglePointWithQuality.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a single-point information with quality descriptor (SIQ) information element.
28 | */
29 | public class IeSinglePointWithQuality extends IeAbstractQuality {
30 |
31 | public IeSinglePointWithQuality(boolean on, boolean blocked, boolean substituted, boolean notTopical,
32 | boolean invalid) {
33 | super(blocked, substituted, notTopical, invalid);
34 |
35 | if (on) {
36 | value |= 0x01;
37 | }
38 | }
39 |
40 | IeSinglePointWithQuality(DataInputStream is) throws IOException {
41 | super(is);
42 | }
43 |
44 | public boolean isOn() {
45 | return (value & 0x01) == 0x01;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "Single Point, is on: " + isOn() + ", " + super.toString();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeSingleProtectionEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a single event of protection equipment (SEP) information element.
28 | */
29 | public class IeSingleProtectionEvent extends InformationElement {
30 |
31 | private int value;
32 |
33 | public IeSingleProtectionEvent(EventState eventState, boolean elapsedTimeInvalid, boolean blocked,
34 | boolean substituted, boolean notTopical, boolean eventInvalid) {
35 |
36 | value = 0;
37 |
38 | switch (eventState) {
39 | case OFF:
40 | value |= 0x01;
41 | break;
42 | case ON:
43 | value |= 0x02;
44 | break;
45 | default:
46 | break;
47 | }
48 |
49 | if (elapsedTimeInvalid) {
50 | value |= 0x08;
51 | }
52 | if (blocked) {
53 | value |= 0x10;
54 | }
55 | if (substituted) {
56 | value |= 0x20;
57 | }
58 | if (notTopical) {
59 | value |= 0x40;
60 | }
61 | if (eventInvalid) {
62 | value |= 0x80;
63 | }
64 | }
65 |
66 | IeSingleProtectionEvent(DataInputStream is) throws IOException {
67 | value = (is.readByte() & 0xff);
68 | }
69 |
70 | @Override
71 | int encode(byte[] buffer, int i) {
72 | buffer[i] = (byte) value;
73 | return 1;
74 | }
75 |
76 | public EventState getEventState() {
77 | switch (value & 0x03) {
78 | case 1:
79 | return EventState.OFF;
80 | case 2:
81 | return EventState.ON;
82 | default:
83 | return EventState.INDETERMINATE;
84 | }
85 | }
86 |
87 | public boolean isElapsedTimeInvalid() {
88 | return (value & 0x08) == 0x08;
89 | }
90 |
91 | public boolean isBlocked() {
92 | return (value & 0x10) == 0x10;
93 | }
94 |
95 | public boolean isSubstituted() {
96 | return (value & 0x20) == 0x20;
97 | }
98 |
99 | public boolean isNotTopical() {
100 | return (value & 0x40) == 0x40;
101 | }
102 |
103 | public boolean isEventInvalid() {
104 | return (value & 0x80) == 0x80;
105 | }
106 |
107 | @Override
108 | public String toString() {
109 | return "Single protection event, elapsed time invalid: " + isElapsedTimeInvalid() + ", blocked: " + isBlocked()
110 | + ", substituted: " + isSubstituted() + ", not topical: " + isNotTopical() + ", event invalid: "
111 | + isEventInvalid();
112 | }
113 |
114 | public enum EventState {
115 | INDETERMINATE,
116 | OFF,
117 | ON;
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeStatusAndStatusChanges.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a status and status change detection (SCD) information element.
28 | */
29 | public class IeStatusAndStatusChanges extends InformationElement {
30 |
31 | private final int value;
32 |
33 | /**
34 | * Creates a SCD (status and status change detection) information element.
35 | *
36 | * @param value the bits of value represent the status and status changed bits. Bit1 (the least significant bit) of
37 | * value represents the first status changed detection bit. Bit17 of value represents the first status
38 | * bit.
39 | */
40 | public IeStatusAndStatusChanges(int value) {
41 |
42 | this.value = value;
43 | }
44 |
45 | IeStatusAndStatusChanges(DataInputStream is) throws IOException {
46 | value = is.readInt();
47 | }
48 |
49 | @Override
50 | int encode(byte[] buffer, int i) {
51 | buffer[i++] = (byte) (value >> 24);
52 | buffer[i++] = (byte) (value >> 16);
53 | buffer[i++] = (byte) (value >> 8);
54 | buffer[i] = (byte) value;
55 | return 4;
56 | }
57 |
58 | public int getValue() {
59 | return value;
60 | }
61 |
62 | /**
63 | * Returns true if the status at the given position is ON(1) and false otherwise.
64 | *
65 | * @param position the position in the status bitstring. Range: 1-16. Status 1 is bit 17 and status 16 is bit 32 of the
66 | * value returned by getValue().
67 | * @return true if the status at the given position is ON(1) and false otherwise.
68 | */
69 | public boolean getStatus(int position) {
70 | if (position < 1 || position > 16) {
71 | throw new IllegalArgumentException("Position out of bound. Should be between 1 and 16.");
72 | }
73 | return (((value >> (position - 17)) & 0x01) == 0x01);
74 | }
75 |
76 | /**
77 | * Returns true if the status at the given position has changed and false otherwise.
78 | *
79 | * @param position the position in the status changed bitstring. Range: 1-16. Status changed 1 is bit 1 and status 16 is
80 | * bit 16 of the value returned by getValue().
81 | * @return true if the status at the given position has changed and false otherwise.
82 | */
83 | public boolean hasStatusChanged(int position) {
84 | if (position < 1 || position > 16) {
85 | throw new IllegalArgumentException("Position out of bound. Should be between 1 and 16.");
86 | }
87 | return (((value >> (position - 1)) & 0x01) == 0x01);
88 | }
89 |
90 | @Override
91 | public String toString() {
92 | StringBuilder sb1 = new StringBuilder();
93 | sb1.append(Integer.toHexString(value >>> 16));
94 | while (sb1.length() < 4) {
95 | sb1.insert(0, '0'); // pad with leading zero if needed
96 | }
97 |
98 | StringBuilder sb2 = new StringBuilder();
99 | sb2.append(Integer.toHexString(value & 0xffff));
100 | while (sb2.length() < 4) {
101 | sb2.insert(0, '0'); // pad with leading zero if needed
102 | }
103 |
104 | return "Status and status changes (first bit = LSB), states: " + sb1.toString() + ", state changes: "
105 | + sb2.toString();
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeStatusOfFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.util.Arrays;
26 | import java.util.HashSet;
27 | import java.util.Set;
28 |
29 | /**
30 | * Represents a status of file (SOF) information element.
31 | */
32 | public class IeStatusOfFile extends InformationElement {
33 |
34 | private final int status;
35 | private final Set flags;
36 |
37 | public IeStatusOfFile(int status, Flag... flags) {
38 | this(status, new HashSet<>(Arrays.asList(flags)));
39 | }
40 |
41 | public IeStatusOfFile(int status, Set flags) {
42 | this.status = status;
43 | this.flags = flags;
44 | }
45 |
46 | static IeStatusOfFile decode(DataInputStream is) throws IOException {
47 | int b1 = is.readUnsignedByte();
48 | int status = b1 & 0x1f;
49 |
50 | Set flags = Flag.flagsFor(b1);
51 |
52 | return new IeStatusOfFile(status, flags);
53 | }
54 |
55 | @Override
56 | int encode(byte[] buffer, int i) {
57 | buffer[i] = (byte) status;
58 | for (Flag f : flags) {
59 | buffer[i] |= (byte) f.mask;
60 | }
61 | return 1;
62 | }
63 |
64 | public int getStatus() {
65 | return status;
66 | }
67 |
68 | public Set getFlags() {
69 | return flags;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return "Status of file: " + status + ", last file of directory: " + flags.contains(Flag.LAST_FILE_OF_DIRECTORY)
75 | + ", name defines directory: " + flags.contains(Flag.NAME_DEFINES_DIRECTORY) + ", transfer is active: "
76 | + flags.contains(Flag.TRANSFER_IS_ACTIVE);
77 | }
78 |
79 | public enum Flag {
80 | LAST_FILE_OF_DIRECTORY(0x20),
81 | NAME_DEFINES_DIRECTORY(0x40),
82 | TRANSFER_IS_ACTIVE(0x80);
83 |
84 | private int mask;
85 |
86 | private Flag(int mask) {
87 | this.mask = mask;
88 | }
89 |
90 | private static Set flagsFor(int b) {
91 | HashSet res = new HashSet<>();
92 | for (Flag v : values()) {
93 | if ((v.mask & b) != v.mask) {
94 | continue;
95 | }
96 | res.add(v);
97 | }
98 | return res;
99 | }
100 |
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeTestSequenceCounter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | /**
27 | * Represents a test sequence Counter (TSC) information element.
28 | */
29 | public class IeTestSequenceCounter extends InformationElement {
30 |
31 | private static final int LOWER_BOUND = 0;
32 | private static final int UPPER_BOUND = 65535; // 2^16 - 1
33 |
34 | private final int value;
35 |
36 | public IeTestSequenceCounter(int value) {
37 | if (value < LOWER_BOUND || value > UPPER_BOUND) {
38 | throw new IllegalArgumentException("Value has to be in the range 0..65535");
39 | }
40 |
41 | this.value = value;
42 | }
43 |
44 | static IeTestSequenceCounter decode(DataInputStream is) throws IOException {
45 | return new IeTestSequenceCounter(is.readUnsignedByte() | (is.readUnsignedByte() << 8));
46 | }
47 |
48 | @Override
49 | int encode(byte[] buffer, int i) {
50 |
51 | buffer[i++] = (byte) value;
52 | buffer[i] = (byte) (value >> 8);
53 |
54 | return 2;
55 | }
56 |
57 | public int getValue() {
58 | return value;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "Test sequence counter: " + getValue();
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeTime16.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.util.Calendar;
26 |
27 | /**
28 | * Represents a two octet binary time (CP16Time2a) information element.
29 | */
30 | public class IeTime16 extends InformationElement {
31 |
32 | private final byte[] value = new byte[2];
33 |
34 | public IeTime16(long timestamp) {
35 | Calendar calendar = Calendar.getInstance();
36 | calendar.setTimeInMillis(timestamp);
37 |
38 | int ms = calendar.get(Calendar.MILLISECOND) + 1000 * calendar.get(Calendar.SECOND);
39 |
40 | value[0] = (byte) ms;
41 | value[1] = (byte) (ms >> 8);
42 | }
43 |
44 | public IeTime16(int timeInMs) {
45 |
46 | int ms = timeInMs % 60000;
47 | value[0] = (byte) ms;
48 | value[1] = (byte) (ms >> 8);
49 | }
50 |
51 | IeTime16(DataInputStream is) throws IOException {
52 | is.readFully(value);
53 | }
54 |
55 | @Override
56 | int encode(byte[] buffer, int i) {
57 | System.arraycopy(value, 0, buffer, i, 2);
58 | return 2;
59 | }
60 |
61 | public int getTimeInMs() {
62 | return (value[0] & 0xff) + ((value[1] & 0xff) << 8);
63 | }
64 |
65 | @Override
66 | public String toString() {
67 | return "Time16, time in ms: " + getTimeInMs();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeTime24.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.util.Calendar;
26 |
27 | /**
28 | * Represents a three octet binary time (CP24Time2a) information element.
29 | */
30 | public class IeTime24 extends InformationElement {
31 |
32 | private final byte[] value = new byte[3];
33 |
34 | public IeTime24(long timestamp) {
35 | Calendar calendar = Calendar.getInstance();
36 | calendar.setTimeInMillis(timestamp);
37 |
38 | int ms = calendar.get(Calendar.MILLISECOND) + 1000 * calendar.get(Calendar.SECOND);
39 |
40 | value[0] = (byte) ms;
41 | value[1] = (byte) (ms >> 8);
42 | value[2] = (byte) calendar.get(Calendar.MINUTE);
43 | }
44 |
45 | public IeTime24(int timeInMs) {
46 |
47 | int ms = timeInMs % 60000;
48 | value[0] = (byte) ms;
49 | value[1] = (byte) (ms >> 8);
50 | value[2] = (byte) (timeInMs / 60000);
51 | }
52 |
53 | IeTime24(DataInputStream is) throws IOException {
54 | is.readFully(value);
55 | }
56 |
57 | @Override
58 | int encode(byte[] buffer, int i) {
59 | System.arraycopy(value, 0, buffer, i, 3);
60 | return 3;
61 | }
62 |
63 | public int getTimeInMs() {
64 | return (value[0] & 0xff) + ((value[1] & 0xff) << 8) + value[2] * 60000;
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "Time24, time in ms: " + getTimeInMs();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/IeValueWithTransientState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 | import java.text.MessageFormat;
26 |
27 | /**
28 | * Represents a value with transient state indication (VTI) information element.
29 | */
30 | public class IeValueWithTransientState extends InformationElement {
31 |
32 | private final int value;
33 | private final boolean transientState;
34 |
35 | /**
36 | * Creates a VTI (value with transient state indication) information element.
37 | *
38 | * @param value value between -64 and 63
39 | * @param transientState true if in transient state
40 | */
41 | public IeValueWithTransientState(int value, boolean transientState) {
42 |
43 | if (value < -64 || value > 63) {
44 | throw new IllegalArgumentException("Value has to be in the range -64..63");
45 | }
46 |
47 | this.value = value;
48 | this.transientState = transientState;
49 |
50 | }
51 |
52 | IeValueWithTransientState(DataInputStream is) throws IOException {
53 | int b1 = (is.readByte() & 0xff);
54 |
55 | transientState = ((b1 & 0x80) == 0x80);
56 |
57 | if ((b1 & 0x40) == 0x40) {
58 | value = b1 | 0xffffff80;
59 | } else {
60 | value = b1 & 0x3f;
61 | }
62 |
63 | }
64 |
65 | @Override
66 | int encode(byte[] buffer, int i) {
67 |
68 | if (transientState) {
69 | buffer[i] = (byte) (value | 0x80);
70 | } else {
71 | buffer[i] = (byte) (value & 0x7f);
72 | }
73 |
74 | return 1;
75 |
76 | }
77 |
78 | public int getValue() {
79 | return value;
80 | }
81 |
82 | public boolean getTransientState() {
83 | return transientState;
84 | }
85 |
86 | @Override
87 | public String toString() {
88 | return MessageFormat.format("Value with transient state, value: {0}, transient state: {1}.", getValue(),
89 | getTransientState());
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/InformationElement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | public abstract class InformationElement {
24 |
25 | abstract int encode(byte[] buffer, int i);
26 |
27 | @Override
28 | public abstract String toString();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/ie/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | /**
22 | * This package contains all information elements.
23 | */
24 | package org.openmuc.j60870.ie;
25 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/internal/ByteStreamHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal;
22 |
23 | import java.io.EOFException;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 |
27 | public final class ByteStreamHelper {
28 |
29 | public static void readFully(InputStream is, byte[] buffer) throws IOException {
30 | readFully(is, buffer, 0, buffer.length);
31 | }
32 |
33 | public static void readFully(InputStream is, byte[] buffer, int off, int len) throws IOException {
34 | do {
35 | int bytesRead = is.read(buffer, off, len);
36 | if (bytesRead == -1) {
37 | throw new EOFException("End of input stream reached.");
38 | }
39 | len -= bytesRead;
40 | off += bytesRead;
41 | } while (len > 0);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/internal/ExtendedDataInputStream.java:
--------------------------------------------------------------------------------
1 | /* Any copyright is dedicated to the Public Domain.
2 | * http://creativecommons.org/publicdomain/zero/1.0/ */
3 | package org.openmuc.j60870.internal;
4 |
5 | import java.io.DataInputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 |
9 | public class ExtendedDataInputStream extends DataInputStream {
10 |
11 | private static final int INTEGER_BYTES = 4;
12 | private static final int SHORT_BYTES = 2;
13 |
14 | public ExtendedDataInputStream(InputStream in) {
15 | super(in);
16 | }
17 |
18 | public int readLittleEndianInt() throws IOException {
19 | return (int) readNLittleEndianBytes(INTEGER_BYTES);
20 | }
21 |
22 | public long readLittleEndianUnsignedInt() throws IOException {
23 | return readLittleEndianInt() & 0xffffffffL;
24 | }
25 |
26 | public short readLittleEndianShort() throws IOException {
27 | return (short) readNLittleEndianBytes(SHORT_BYTES);
28 | }
29 |
30 | public int readLittleEndianUnsignedShort() throws IOException {
31 | return readLittleEndianShort() & 0xffff;
32 | }
33 |
34 | private long readNLittleEndianBytes(int n) throws IOException {
35 | long res = 0;
36 | for (long i = 0; i < n; ++i) {
37 | res |= (long) readUnsignedByte() << 8L * i;
38 | }
39 | return res;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/internal/HexUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal;
22 |
23 | public class HexUtils {
24 |
25 | private static final String HEXES = "0123456789ABCDEF";
26 |
27 | private HexUtils() {
28 | // hide it
29 | }
30 |
31 | public static String bytesToHex(byte[] bytes) {
32 | if (bytes == null) {
33 | return null;
34 | }
35 | final StringBuilder hex = new StringBuilder(2 * bytes.length);
36 | for (final byte b : bytes) {
37 | hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
38 | }
39 | return hex.toString();
40 | }
41 |
42 | public static byte[] hexToBytes(String hexString) {
43 | byte[] bytes = new byte[hexString.length() / 2];
44 | int index;
45 |
46 | for (int i = 0; i < bytes.length; i++) {
47 | index = i * 2;
48 | bytes[i] = (byte) Integer.parseInt(hexString.substring(index, index + 2), 16);
49 | }
50 | return bytes;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/internal/SerialExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal;
22 |
23 | import java.util.ArrayDeque;
24 | import java.util.Queue;
25 | import java.util.concurrent.Executor;
26 |
27 | public class SerialExecutor implements Executor {
28 |
29 | private final Queue tasks = new ArrayDeque<>();
30 | private final Executor executor;
31 | private final Object lock = new Object();
32 | private Runnable active;
33 |
34 | public SerialExecutor(Executor executor) {
35 | this.executor = executor;
36 | }
37 |
38 | @Override
39 | public void execute(final Runnable r) {
40 | synchronized (lock) {
41 | tasks.offer(new Runnable() {
42 | @Override
43 | public void run() {
44 | try {
45 | r.run();
46 | } finally {
47 | scheduleNext();
48 | }
49 | }
50 | });
51 | if (active == null) {
52 | scheduleNext();
53 | }
54 | }
55 | }
56 |
57 | private void scheduleNext() {
58 | synchronized (lock) {
59 | if ((active = tasks.poll()) != null) {
60 | executor.execute(active);
61 | }
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/org/openmuc/j60870/internal/StartBytesSimpleReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.internal;
22 |
23 | import java.io.DataInputStream;
24 | import java.io.IOException;
25 |
26 | public final class StartBytesSimpleReader {
27 |
28 | private final byte[] startBytes;
29 | private final DataInputStream is;
30 |
31 | /**
32 | * Creates a StartBytesSimpleReader.
33 | *
34 | * @param startBytes the start bytes to read
35 | * @param is the input stream to read the start bytes from
36 | */
37 | public StartBytesSimpleReader(byte[] startBytes, DataInputStream is) {
38 | this.startBytes = startBytes;
39 | this.is = is;
40 | }
41 |
42 | /**
43 | * Reads from the input stream until the start bytes are received. The start bytes are put in the
44 | * {@code destBuffer}. Any bytes that do not match the start byte sequence are discarded. If reading from the input
45 | * stream causes an IOException it is propagated.
46 | *
47 | * @throws IOException if an IOException is thrown reading from the input stream
48 | */
49 | public void readStartBytes() throws IOException {
50 | byte b = is.readByte();
51 | whileLoop:
52 | while (true) {
53 | for (int i = 0; i < startBytes.length; i++) {
54 | if (b != startBytes[i]) {
55 | if (i == 0) {
56 | b = is.readByte();
57 | }
58 | continue whileLoop;
59 | }
60 | if (i != (startBytes.length - 1)) {
61 | b = is.readByte();
62 | }
63 | }
64 | return;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/CommonBuilderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import junitparams.JUnitParamsRunner;
24 | import org.junit.Before;
25 | import org.junit.Test;
26 | import org.junit.runner.RunWith;
27 | import org.openmuc.j60870.Server.Builder;
28 |
29 | @RunWith(JUnitParamsRunner.class)
30 | public class CommonBuilderTest {
31 | private Builder builder;
32 |
33 | @Before
34 | public void init() {
35 | builder = Server.builder();
36 | }
37 |
38 | public void setTime(int t1, int t2, int t3) {
39 | System.out.println("t1=" + t1 + ", t2=" + t2 + ", t3=" + t3);
40 | try {
41 | builder.setMaxTimeNoAckReceived(t1).setMaxTimeNoAckSent(t2).setMaxIdleTime(t3);
42 |
43 | } catch (Exception e) {
44 | System.out.println(e.getMessage());
45 | throw e;
46 | }
47 | }
48 |
49 | @Test(expected = IllegalArgumentException.class)
50 | public void testT2BiggerThenT1() {
51 | setTime(15000, 16000, 20000);
52 | }
53 |
54 | @Test(expected = IllegalArgumentException.class)
55 | public void testT3SmallerThenT1() {
56 | setTime(15000, 10000, 14000);
57 | }
58 |
59 | @Test(expected = IllegalArgumentException.class)
60 | public void testT1toSmall() {
61 | setTime(Integer.MIN_VALUE, 10000, 20000);
62 | }
63 |
64 | @Test(expected = IllegalArgumentException.class)
65 | public void testT1toBig() {
66 | setTime(Integer.MAX_VALUE, 10000, 20000);
67 | }
68 |
69 | @Test(expected = IllegalArgumentException.class)
70 | public void testT2toSmall() {
71 | setTime(15000, Integer.MIN_VALUE, 20000);
72 | }
73 |
74 | @Test(expected = IllegalArgumentException.class)
75 | public void testT2toBig() {
76 | setTime(15000, Integer.MAX_VALUE, 20000);
77 | }
78 |
79 | @Test(expected = IllegalArgumentException.class)
80 | public void testT3toSmall() {
81 | setTime(15000, 10000, Integer.MIN_VALUE);
82 | }
83 |
84 | @Test(expected = IllegalArgumentException.class)
85 | public void testT3toBig() {
86 | setTime(15000, 10000, Integer.MAX_VALUE);
87 | }
88 |
89 | @Test
90 | public void testTimeOK() {
91 | setTime(15000, 10000, 20000);
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/TestUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import org.openmuc.j60870.internal.HexUtils;
24 |
25 | import java.io.IOException;
26 | import java.net.ServerSocket;
27 | import java.util.Random;
28 |
29 | public class TestUtils {
30 | private static final int MIN_PORT_NUMBER = 2024;
31 | private static final int MAX_PORT_NUMBER = 65535;
32 | private static final Random RANDOM = new Random();
33 | private static final int MAX_TRIES = 50;
34 |
35 | public static byte[] STARTDT_ACT_BYTES = HexUtils.hexToBytes("680407000000");
36 | public static byte[] STARTDT_CON_BYTES = HexUtils.hexToBytes("68040B000000");
37 | public static byte[] STOPDT_ACT_BYTES = HexUtils.hexToBytes("680413000000");
38 | public static byte[] STOPDT_CON_BYTES = HexUtils.hexToBytes("680423000000");
39 |
40 | public static int getAvailablePort() {
41 | int port = MIN_PORT_NUMBER;
42 | boolean isAvailable = false;
43 | int tries = 0;
44 |
45 | while (!isAvailable && tries < MAX_TRIES) {
46 | port = RANDOM.nextInt((MAX_PORT_NUMBER - MIN_PORT_NUMBER) + 1) + MIN_PORT_NUMBER;
47 | try (ServerSocket ss = new ServerSocket(port);) {
48 | ss.setReuseAddress(true);
49 | isAvailable = ss.isBound();
50 | } catch (IOException e) {
51 | // port is not available
52 | }
53 | tries++;
54 | }
55 | if (!isAvailable) {
56 | throw new RuntimeException("No available port found after " + MAX_TRIES + " tries");
57 | }
58 |
59 | return port;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/TimeoutManagerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import org.awaitility.Awaitility;
24 | import org.junit.Test;
25 | import org.mockito.invocation.InvocationOnMock;
26 | import org.mockito.stubbing.Answer;
27 | import org.powermock.api.mockito.PowerMockito;
28 |
29 | import java.util.concurrent.Callable;
30 | import java.util.concurrent.ExecutorService;
31 | import java.util.concurrent.Executors;
32 | import java.util.concurrent.TimeUnit;
33 |
34 | import static org.junit.Assert.assertEquals;
35 | import static org.mockito.Mockito.verify;
36 | import static org.powermock.api.mockito.PowerMockito.*;
37 | import static org.powermock.reflect.Whitebox.setInternalState;
38 |
39 | public class TimeoutManagerTest {
40 |
41 | @Test
42 | public void test1() throws Exception {
43 | final long timeout = 200;
44 |
45 | TimeoutManager tm = PowerMockito.spy(new TimeoutManager());
46 | final TimeoutTask task = mock(TimeoutTask.class);
47 | setInternalState(task, "timeout", timeout);
48 |
49 | doCallRealMethod().when(task).updateDueTime();
50 | doCallRealMethod().when(task).sleepTimeFromDueTime();
51 | doCallRealMethod().when(task).executeManually();
52 | doCallRealMethod().when(task).isDone();
53 |
54 | ExecutorService exec = Executors.newSingleThreadExecutor();
55 | exec.execute(tm);
56 | tm.addTimerTask(task);
57 |
58 | final long t0 = System.currentTimeMillis();
59 | doAnswer(new Answer() {
60 |
61 | @Override
62 | public Void answer(InvocationOnMock invocation) throws Throwable {
63 | long sleepTime = System.currentTimeMillis() - t0;
64 |
65 | assertEquals(timeout, sleepTime, 40D);
66 | return null;
67 | }
68 | }).when(task).execute();
69 |
70 | Awaitility.await().atMost(1, TimeUnit.SECONDS).until(new Callable() {
71 |
72 | @Override
73 | public Boolean call() throws Exception {
74 | return task.isDone();
75 | }
76 | });
77 |
78 | // check if execute has been called
79 | verify(tm).run();
80 | verify(task).execute();
81 |
82 | exec.shutdown();
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/UtilTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertEquals;
26 |
27 | public class UtilTest {
28 |
29 | @Test
30 | public void testSetGetValue() {
31 | assertEquals(327832, Util.convertToInformationObjectAddress(152, 0, 5));
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/WrongTypeIdITest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870;
22 |
23 | import org.junit.Assert;
24 | import org.junit.Test;
25 | import org.openmuc.j60870.internal.ByteStreamHelper;
26 | import org.openmuc.j60870.internal.HexUtils;
27 |
28 | import java.io.IOException;
29 | import java.io.InputStream;
30 | import java.io.OutputStream;
31 | import java.net.Socket;
32 | import java.util.ArrayList;
33 | import java.util.Arrays;
34 |
35 | public class WrongTypeIdITest {
36 |
37 | private static final int PORT = TestUtils.getAvailablePort();
38 |
39 | @Test
40 | public void testWrongTypeIdITest() throws Exception {
41 | Server server = Server.builder()
42 | .setPort(PORT)
43 | .setMaxNumOfOutstandingIPdus(32_767)
44 | .setAllowedASduTypes(new ArrayList<>())
45 | .build();
46 | try {
47 | server.start(new ServerListener());
48 |
49 | Socket socket = new Socket("localhost", PORT);
50 | socket.setSoTimeout(200_000);
51 |
52 | try {
53 | InputStream is = socket.getInputStream();
54 | OutputStream os = socket.getOutputStream();
55 |
56 | byte[] startdtAct = HexUtils.hexToBytes("680407000000");
57 | os.write(startdtAct);
58 |
59 | byte[] startdtCon = new byte[6];
60 | ByteStreamHelper.readFully(is, startdtCon);
61 | Assert.assertArrayEquals(HexUtils.hexToBytes("68040B000000"), startdtCon);
62 |
63 | byte[] malformedUnsupportedTypeApdu = HexUtils
64 | .hexToBytes("6816000000002D01060039000000008D670A99130D190118");
65 | os.write(malformedUnsupportedTypeApdu);
66 |
67 | byte[] response = new byte[malformedUnsupportedTypeApdu.length];
68 | ByteStreamHelper.readFully(is, response);
69 |
70 | byte[] expectedResponse = Arrays.copyOf(malformedUnsupportedTypeApdu,
71 | malformedUnsupportedTypeApdu.length);
72 | expectedResponse[4] = 0x02;
73 | expectedResponse[8] = (byte) (0x40 | CauseOfTransmission.UNKNOWN_TYPE_ID.getId());
74 | Assert.assertArrayEquals(expectedResponse, response);
75 | } finally {
76 | socket.close();
77 | }
78 | } finally {
79 | server.stop();
80 | }
81 | }
82 |
83 | class ServerListener implements ServerEventListener {
84 |
85 | @Override
86 | public ConnectionEventListener connectionIndication(Connection connection) {
87 | System.out.println("Server: connection indication");
88 | return new ConnectionListener();
89 | }
90 |
91 | @Override
92 | public void serverStoppedListeningIndication(IOException e) {
93 | System.out.println("Server stopped listening: " + e);
94 | }
95 |
96 | @Override
97 | public void connectionAttemptFailed(IOException e) {
98 | System.out.println("Server: Connection attempt failed: " + e);
99 | }
100 | }
101 |
102 | class ConnectionListener implements ConnectionEventListener {
103 |
104 | @Override
105 | public void newASdu(Connection connection, ASdu aSdu) {
106 | System.out.println("New Asdu: " + aSdu);
107 | }
108 |
109 | @Override
110 | public void connectionClosed(Connection connection, IOException cause) {
111 | System.out.println("Connection closed");
112 | }
113 |
114 | @Override
115 | public void dataTransferStateChanged(Connection connection, boolean stopped) {
116 | System.out.println("Data transfer state changed: " + (stopped ? "stopped" : "started"));
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/ie/CP56Time2aTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import org.junit.After;
24 | import org.junit.Before;
25 | import org.junit.Test;
26 |
27 | import java.util.TimeZone;
28 |
29 | import static org.junit.Assert.assertArrayEquals;
30 | import static org.junit.Assert.assertEquals;
31 | import static org.openmuc.j60870.internal.HexUtils.hexToBytes;
32 |
33 | public class CP56Time2aTest {
34 |
35 | TimeZone cet = TimeZone.getTimeZone("CET");
36 | TimeZone systemDefault;
37 |
38 | @Before
39 | public void setup() {
40 | systemDefault = TimeZone.getDefault();
41 | TimeZone.setDefault(cet);
42 | }
43 |
44 | @After
45 | public void init() {
46 | TimeZone.setDefault(systemDefault);
47 | }
48 |
49 | @After
50 | public void deinit() {
51 | TimeZone cet = TimeZone.getTimeZone("CET");
52 | TimeZone.setDefault(cet);
53 | }
54 |
55 | @Test
56 | public void testTimestampToCalendarInvalid() {
57 | // Time56: 29-10-13 16:30:54:596, invalid
58 | testIeTime56(1383060654596L, true, "CET", false, hexToBytes("44D59E105D0A0D"));
59 | }
60 |
61 | @Test
62 | public void testDSTTimestampToCalendarInvalid() {
63 | // Time56: 06-07-18 15:17:23:000 DST, invalid
64 | testIeTime56(1530883043000L, true, "CET", true, hexToBytes("D859918FA60712"));
65 | }
66 |
67 | @Test
68 | public void testDstTimestampToCalendar() {
69 | // Time56: 28-10-18 02:59:59:999 DST
70 | testIeTime56(1540688399999L, false, "CET", true, hexToBytes("5FEA3B82FC0A12"));
71 | }
72 |
73 | @Test
74 | public void testTimestampToCalendar() {
75 | // Time56: 28-10-18 02:00:00:000
76 | testIeTime56(1540688400000L, false, "CET", false, hexToBytes("00000002FC0A12"));
77 | }
78 |
79 | @Test
80 | public void summertime_20181028_0100() {
81 | // 28.10.2018 01:00:30 CET DST (UTC+2)
82 | IeTime56 ts = new IeTime56(new byte[]{0x30, 0x75, 0x00, (byte) 0x81, (byte) 0xFC, 0x0a, 0x12});
83 | assertEquals(1540681230000L, ts.getTimestamp());
84 | }
85 |
86 | @Test
87 | public void summertime_20181028_0200() {
88 | // 28.10.2018 02:00:30 CET DST (UTC+2)
89 | IeTime56 ts = new IeTime56(new byte[]{(byte) 0x30, 0x75, 0x00, (byte) 0x82, (byte) 0xfc, 0x0a, 0x12});
90 | assertEquals(1540684830000L, ts.getTimestamp());
91 | }
92 |
93 | @Test
94 | public void standardtime_20181028_0200() {
95 | // 28.10.2018 02:00:30 CET (UTC+1)
96 | IeTime56 ts = new IeTime56(new byte[]{0x30, 0x75, 0x00, (byte) 0x02, (byte) 0xfc, 0x0a, 0x12});
97 | assertEquals(1540688430000L, ts.getTimestamp());
98 | }
99 |
100 | @Test
101 | public void standardtime_20190331_0100() {
102 | // 31.03.2019 01:00:30 CET (UTC+1)
103 | IeTime56 ts = new IeTime56(new byte[]{0x30, 0x75, 0x00, (byte) 0x01, (byte) 0xff, 0x03, 0x13});
104 | assertEquals(1553990430000L, ts.getTimestamp());
105 | }
106 |
107 | @Test
108 | public void summtertime_20190331_0300() {
109 | // 31.03.2019 03:00:30 CET DST (UTC+2)
110 | IeTime56 ts = new IeTime56(new byte[]{0x30, 0x75, 0x00, (byte) 0x83, (byte) 0xff, 0x03, 0x13});
111 | assertEquals(1553994030000L, ts.getTimestamp());
112 | }
113 |
114 | private void testIeTime56(long timestamp, boolean invalid, String timezone, boolean expectedDST,
115 | byte[] expectedEncodedBytes) {
116 | TimeZone timeZone = TimeZone.getTimeZone(timezone);
117 |
118 | IeTime56 time = new IeTime56(timestamp, timeZone, invalid);
119 |
120 | byte[] buffer = new byte[7];
121 | int length = time.encode(buffer, 0);
122 |
123 | assertEquals(7, length);
124 |
125 | assertEquals(invalid, time.isInvalid());
126 |
127 | assertEquals(expectedDST, time.isSummerTime());
128 | assertArrayEquals(expectedEncodedBytes, buffer);
129 |
130 | assertEquals(timestamp, time.getTimestamp());
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/ie/IeBinaryStateInformationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertArrayEquals;
26 | import static org.junit.Assert.assertEquals;
27 |
28 | public class IeBinaryStateInformationTest {
29 |
30 | @Test
31 | public void testSetGetValue() {
32 |
33 | byte[] bits = new byte[]{(byte) 0x7f, 0, (byte) 0xff, (byte) 0x80};
34 |
35 | IeBinaryStateInformation ieBinaryStateInformation = new IeBinaryStateInformation(bits);
36 |
37 | assertEquals(2130771840, ieBinaryStateInformation.getValue());
38 | assertArrayEquals(bits, ieBinaryStateInformation.getValueAsByteArray());
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/ie/IeTestSequenceCounterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import junitparams.JUnitParamsRunner;
24 | import junitparams.Parameters;
25 | import org.junit.Test;
26 | import org.junit.runner.RunWith;
27 |
28 | @RunWith(JUnitParamsRunner.class)
29 | public class IeTestSequenceCounterTest {
30 |
31 | @Test(expected = IllegalArgumentException.class)
32 | @Parameters({"-1", "65536"})
33 | public void testConstrcutorRange(int i) throws Exception {
34 | new IeTestSequenceCounter(i);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/org/openmuc/j60870/ie/IeValueWithTransientTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014-2024 Fraunhofer ISE
3 | *
4 | * This file is part of j60870.
5 | * For more information visit http://www.openmuc.org
6 | *
7 | * j60870 is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * j60870 is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with j60870. If not, see .
19 | *
20 | */
21 | package org.openmuc.j60870.ie;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertEquals;
26 |
27 | public class IeValueWithTransientTest {
28 |
29 | @Test
30 | public void testSetGetValue() {
31 |
32 | IeValueWithTransientState valueWithTransientState = new IeValueWithTransientState(-64, false);
33 |
34 | assertEquals(-64, valueWithTransientState.getValue());
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------