Skip to content

Commit

Permalink
feat: bump version to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gythialy committed Aug 15, 2022
1 parent 5e6adb0 commit 9d85575
Show file tree
Hide file tree
Showing 204 changed files with 76,334 additions and 30,272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Main workflow

on: [push]
on: [ push ]

jobs:
build:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# IEC 60870-5-104
# IEC 60870-5-104

## Overview [![Actions Status](https://github.com/gythialy/j60870/workflows/Main%20workflow/badge.svg)](https://github.com/gythialy/j60870/actions)

This is UNOFFICIAL, fork from [openmuc](https://www.openmuc.org/iec-60870-5-104/).

j60870 is a library implementing the IEC 60870-5-104 communication standard. The library can be used to program clients as well as servers. j60870 is licensed under the GPLv3. In addition we sell j60870 under proprietary licenses if needed. Please contact us if you need another license. Proprietary licenses are negotiated individually.
j60870 is a library implementing the IEC 60870-5-104 communication standard. The library can be used to program clients
as well as servers. j60870 is licensed under the GPLv3. In addition we sell j60870 under proprietary licenses if needed.
Please contact us if you need another license. Proprietary licenses are negotiated individually.

Read the [user guide](https://gythialy.github.io/j60870/) on how to get started with the library.

Expand All @@ -17,4 +19,4 @@ GNU GENERAL PUBLIC LICENSE
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
```
```
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ configure(javaProjects) {
implementation "javax.xml.bind:jaxb-api:2.3.1"
implementation "com.sun.xml.bind:jaxb-core:2.3.0.1"
implementation "com.sun.xml.bind:jaxb-impl:2.3.2"

testCompile group: "junit", name: "junit", version: "4.12"
itestCompile group: "junit", name: "junit", version: "4.12"

Expand Down
98 changes: 56 additions & 42 deletions cli-app/src/main/java/org/openmuc/j60870/app/ConsoleClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-20 Fraunhofer ISE
* Copyright 2014-2022 Fraunhofer ISE
*
* This file is part of j60870.
* For more information visit http://www.openmuc.org
Expand All @@ -20,35 +20,26 @@
*/
package org.openmuc.j60870.app;

import org.openmuc.j60870.*;
import org.openmuc.j60870.ie.IeQualifierOfCounterInterrogation;
import org.openmuc.j60870.ie.IeQualifierOfInterrogation;
import org.openmuc.j60870.ie.IeSingleCommand;
import org.openmuc.j60870.ie.IeTime56;
import org.openmuc.j60870.internal.cli.*;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.openmuc.j60870.ASdu;
import org.openmuc.j60870.CauseOfTransmission;
import org.openmuc.j60870.ClientConnectionBuilder;
import org.openmuc.j60870.Connection;
import org.openmuc.j60870.ConnectionEventListener;
import org.openmuc.j60870.ie.IeQualifierOfInterrogation;
import org.openmuc.j60870.ie.IeSingleCommand;
import org.openmuc.j60870.ie.IeTime56;
import org.openmuc.j60870.internal.cli.Action;
import org.openmuc.j60870.internal.cli.ActionException;
import org.openmuc.j60870.internal.cli.ActionListener;
import org.openmuc.j60870.internal.cli.ActionProcessor;
import org.openmuc.j60870.internal.cli.CliParameter;
import org.openmuc.j60870.internal.cli.CliParameterBuilder;
import org.openmuc.j60870.internal.cli.CliParseException;
import org.openmuc.j60870.internal.cli.CliParser;
import org.openmuc.j60870.internal.cli.IntCliParameter;
import org.openmuc.j60870.internal.cli.StringCliParameter;

public final class ConsoleClient {

private static final String INTERROGATION_ACTION_KEY = "i";
private static final String COUNTER_INTERROGATION_ACTION_KEY = "ci";
private static final String CLOCK_SYNC_ACTION_KEY = "c";
private static final String SINGLE_COMMAND_SELECT = "s";
private static final String SINGLE_COMMAND_EXECUTE = "e";
Expand Down Expand Up @@ -91,15 +82,15 @@ public static void main(String[] args) {
cliParser.parseArguments(args);
} catch (CliParseException e1) {
System.err.println("Error parsing command line parameters: " + e1.getMessage());
println(cliParser.getUsageString());
log(cliParser.getUsageString());
System.exit(1);
}

InetAddress address;
try {
address = InetAddress.getByName(hostParam.getValue());
} catch (UnknownHostException e) {
println("Unknown host: ", hostParam.getValue());
log("Unknown host: ", hostParam.getValue());
return;
}

Expand All @@ -111,7 +102,7 @@ public static void main(String[] args) {
try {
connection = clientConnectionBuilder.build();
} catch (IOException e) {
println("Unable to connect to remote host: ", hostParam.getValue(), ".");
log("Unable to connect to remote host: ", hostParam.getValue(), ".");
return;
}

Expand All @@ -128,27 +119,28 @@ public void run() {

while (!connected && i <= retries) {
try {
println("Send start DT. Try no. " + i);
log("Send start DT. Try no. " + i);
connection.startDataTransfer(new ClientEventListener());
} catch (InterruptedIOException e2) {
if (i == retries) {
println("Starting data transfer timed out. Closing connection. Because of no more retries.");
log("Starting data transfer timed out. Closing connection. Because of no more retries.");
connection.close();
return;
} else {
println("Got Timeout.class Next try.");
log("Got Timeout.class Next try.");
++i;
continue;
}
} catch (IOException e) {
println("Connection closed for the following reason: ", e.getMessage());
log("Connection closed for the following reason: ", e.getMessage());
return;
}
connected = true;
}
println("successfully connected");
log("successfully connected");

actionProcessor.addAction(new Action(INTERROGATION_ACTION_KEY, "interrogation C_IC_NA_1"));
actionProcessor.addAction(new Action(COUNTER_INTERROGATION_ACTION_KEY, "counter interrogation C_CI_NA_1"));
actionProcessor.addAction(new Action(CLOCK_SYNC_ACTION_KEY, "synchronize clocks C_CS_NA_1"));
actionProcessor.addAction(new Action(SINGLE_COMMAND_SELECT, "single command select C_SC_NA_1"));
actionProcessor.addAction(new Action(SINGLE_COMMAND_EXECUTE, "single command execute C_SC_NA_1"));
Expand All @@ -158,10 +150,16 @@ public void run() {
actionProcessor.start();
}

private static void println(String... strings) {
private static void log(String... strings) {
String time = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS ").format(new Date());
println(time, strings);
}

private static void println(String string, String... strings) {
StringBuilder sb = new StringBuilder();
for (String string : strings) {
sb.append(string);
sb.append(string);
for (String s : strings) {
sb.append(s);
}
System.out.println(sb.toString());
}
Expand All @@ -170,20 +168,29 @@ private static class ClientEventListener implements ConnectionEventListener {

@Override
public void newASdu(ASdu aSdu) {
println("\nReceived ASDU:\n", aSdu.toString());
log("\nReceived ASDU:\n", aSdu.toString());
}

@Override
public void connectionClosed(IOException e) {
println("Received connection closed signal. Reason: ");
log("Received connection closed signal. Reason: ");
if (!e.getMessage().isEmpty()) {
println(e.getMessage());
log(e.getMessage());
} else {
println("unknown");
log("unknown");
}
actionProcessor.close();
}

@Override
public void dataTransferStateChanged(boolean stopped) {
String dtState = "started";
if (stopped) {
dtState = "stopped";
}
log("Data transfer was ", dtState);
}

}

private static class ActionExecutor implements ActionListener {
Expand All @@ -192,30 +199,37 @@ public void actionCalled(String actionKey) throws ActionException {
try {
switch (actionKey) {
case INTERROGATION_ACTION_KEY:
println("** Sending general interrogation command.");
log("** Sending general interrogation command.");
connection.interrogation(commonAddrParam.getValue(), CauseOfTransmission.ACTIVATION,
new IeQualifierOfInterrogation(20));
break;
case COUNTER_INTERROGATION_ACTION_KEY:
log("Enter the freeze action: 0=read, 1=counter freeze wo reset, 2=counter freeze with reset, 3=counter reset");
String reference = actionProcessor.getReader().readLine();
log("** Sending counter interrogation command.");
connection.counterInterrogation(commonAddrParam.getValue(), CauseOfTransmission.ACTIVATION,
new IeQualifierOfCounterInterrogation(5, Integer.parseInt(reference)));
break;
case CLOCK_SYNC_ACTION_KEY:
println("** Sending synchronize clocks command.");
log("** Sending synchronize clocks command.");
connection.synchronizeClocks(commonAddrParam.getValue(), new IeTime56(System.currentTimeMillis()));
break;
case SINGLE_COMMAND_SELECT:
println("** Sending single command select.");
log("** Sending single command select.");
connection.singleCommand(commonAddrParam.getValue(), CauseOfTransmission.ACTIVATION, 5000,
new IeSingleCommand(true, 0, true));
break;
case SINGLE_COMMAND_EXECUTE:
println("** Sending single command execute.");
log("** Sending single command execute.");
connection.singleCommand(commonAddrParam.getValue(), CauseOfTransmission.ACTIVATION, 5000,
new IeSingleCommand(false, 0, false));
break;
case SEND_STOPDT:
println("** Sending STOPDT act.");
log("** Sending STOPDT act.");
connection.stopDataTransfer();
break;
case SEND_STARTDT:
println("** Sending STARTDT act.");
log("** Sending STARTDT act.");
connection.startDataTransfer(new ClientEventListener());
break;
default:
Expand All @@ -228,7 +242,7 @@ public void actionCalled(String actionKey) throws ActionException {

@Override
public void quit() {
println("** Closing connection.");
log("** Closing connection.");
connection.close();
}
}
Expand Down
Loading

0 comments on commit 9d85575

Please sign in to comment.