commit 2c702c5b12d0ae02e38f4148e8a1eed62bff8cf8
Author: github-classroom[bot] <66690702+github-classroom[bot]@users.noreply.github.com>
Date: Tue May 2 11:57:51 2023 +0000
Initial commit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..88b6d2a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/.idea/vcs.xml
+/.idea/libraries
+/.idea/jarRepositories.xml
+/.idea/codeStyles
+/.idea/*.xml
+
+# TODO: add your build folder here
\ No newline at end of file
diff --git a/Minecraft.iml b/Minecraft.iml
new file mode 100644
index 0000000..af3f250
--- /dev/null
+++ b/Minecraft.iml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2e9402f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Minecraft Base Project
+
+IntelliJ base project related to Minecraft Lab of 221_SIn & 231_SIn course
\ No newline at end of file
diff --git a/javadoc/hei/allclasses-frame.html b/javadoc/hei/allclasses-frame.html
new file mode 100644
index 0000000..cee097f
--- /dev/null
+++ b/javadoc/hei/allclasses-frame.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+All Classes
+
+
+
+
+
+All Classes
+
+
+
diff --git a/javadoc/hei/allclasses-noframe.html b/javadoc/hei/allclasses-noframe.html
new file mode 100644
index 0000000..f234129
--- /dev/null
+++ b/javadoc/hei/allclasses-noframe.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+All Classes
+
+
+
+
+
+All Classes
+
+
+
diff --git a/javadoc/hei/ch/hevs/isi/utils/Utility.html b/javadoc/hei/ch/hevs/isi/utils/Utility.html
new file mode 100644
index 0000000..3e85ba0
--- /dev/null
+++ b/javadoc/hei/ch/hevs/isi/utils/Utility.html
@@ -0,0 +1,743 @@
+
+
+
+
+
+Utility
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+Prev Class
+Next Class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+java.lang.Object
+
+
+ch.hevs.isi.utils.Utility
+
+
+
+
+
+
+
+
+
+
+
+
+Field Summary
+
+Fields
+
+Modifier and Type
+Field and Description
+
+
+static java.util.Random
+rnd
+Object to get some random values...
+
+
+
+static int
+TCP_BUFFER_SIZE
+Default size for the TCP input stream
+
+
+
+
+
+
+
+
+
+
+Constructor Summary
+
+Constructors
+
+Constructor and Description
+
+
+Utility ()
+
+
+
+
+
+
+
+
+
+Method Summary
+
+All Methods Static Methods Concrete Methods
+
+Modifier and Type
+Method and Description
+
+
+static java.lang.Float
+bytesToFloat (byte[] bytes,
+ int offset,
+ int size)
+Returns a float
value from array of bytes.
+
+
+
+static byte[]
+calculateCRC (byte[] data,
+ int offset,
+ int len)
+Calculates and returns the CRC using the data passed in parameters.
+
+
+
+static boolean
+checkCRC (byte[] data,
+ int offset,
+ int len,
+ byte[] crc)
+Checks the CRC and returns true if it is correct, otherwise false.
+
+
+
+static void
+DEBUG (java.lang.String className,
+ java.lang.String method,
+ java.lang.String msg)
+
+
+static java.io.BufferedReader
+fileParser (java.lang.String path,
+ java.lang.String fileName)
+Method to use to access a file in your resources folder...
+
+
+
+static java.lang.String
+getHexString (byte[] b)
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f).
+
+
+
+static java.lang.String
+getHexString (byte[] b,
+ int offset,
+ int length)
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+
+
+
+static java.lang.String
+getStringRndVal (int factor)
+Retrieves a random value rounded to 2 decimal...
+
+
+
+static java.lang.String
+md5sum (java.lang.String msg)
+Returns the md5 of any input...
+
+
+
+static byte[]
+readBytes (java.io.InputStream in)
+Reads the incoming data from an input stream as long as there is something to read and saved the data in an array
+ of bytes.
+
+
+
+static byte[]
+readLine (java.io.InputStream in)
+Reads a line of text.
+
+
+
+static byte[]
+readNBytes (java.io.InputStream in,
+ int len)
+Reads from the given input stream an amount of bytes and retrieves these data as an array of bytes.
+
+
+
+static void
+sendBytes (java.io.OutputStream out,
+ byte[] toSend,
+ int offset,
+ int length)
+This method sends the content of the buffer
to the given OutputStream
.
+
+
+
+static int
+unsignedByteToSignedInt (byte from)
+Converts an unsigned byte to a signed integer.
+
+
+
+static void
+waitSomeTime (int ms)
+To wait some times ...
+
+
+
+static void
+writeLine (java.io.OutputStream out,
+ byte[] toSend)
+Send the data contained in the given array of bytes through the output
+ stream.
+
+
+
+
+
+
+
+Methods inherited from class java.lang.Object
+clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Constructor Detail
+
+
+
+
+
+Utility
+public Utility()
+
+
+
+
+
+
+
+
+
+Method Detail
+
+
+
+
+
+calculateCRC
+public static byte[] calculateCRC(byte[] data,
+ int offset,
+ int len)
+Calculates and returns the CRC using the data passed in parameters.
+
+Parameters:
+data
- a byte array containing the data to send
+offset
- the offset
+len
- the data length
+Returns:
+byte[] the CRC
+
+
+
+
+
+
+
+
+checkCRC
+public static boolean checkCRC(byte[] data,
+ int offset,
+ int len,
+ byte[] crc)
+Checks the CRC and returns true if it is correct, otherwise false.
+
+Parameters:
+data
- a byte array containing the data to send
+offset
- the offset
+len
- the data length
+crc
- a byte array containing the CRC to check
+Returns:
+boolean true if the CRC is correct, otherwise false
+
+
+
+
+
+
+
+
+
+
+
+
+getHexString
+public static java.lang.String getHexString(byte[] b)
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f). The array of bytes is
+ converted from offset 0 to its end.
+
+Parameters:
+b
- Array of bytes to be converted in HEX string.
+Returns:
+A String representing the HEX values of the given array of bytes.
+
+
+
+
+
+
+
+
+getHexString
+public static java.lang.String getHexString(byte[] b,
+ int offset,
+ int length)
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+
+Parameters:
+b
- The byte array to convert in HEX string
+offset
- The index where we start to convert from.
+length
- The amount of bytes to convert in HEX string
+Returns:
+A String representing the HEX values of the selected bytes of the array.
+
+
+
+
+
+
+
+
+
+
+
+
+readBytes
+public static byte[] readBytes(java.io.InputStream in)
+ throws java.io.IOException
+Reads the incoming data from an input stream as long as there is something to read and saved the data in an array
+ of bytes.
+
+ The method is blocking ! This method blocks until input data is available, end of file is detected, or an
+ exception is thrown.
+
+ If the length of of read data is zero, then no bytes are read and an empty array of bytes is returned; otherwise,
+ there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the
+ file, the value -1 is returned; otherwise, at least one byte is read and returned as an array of bytes.
+
+Parameters:
+in
- The input Stream where to read the data coming from.
+Returns:
+The read data as an array of bytes
. Or null if the has been closed by the peer while
+ waiting for incoming data.
+Throws:
+java.io.IOException
- If the first byte cannot be read for any reason other than the end of the file, if the input
+ stream has been closed, or if some other I/O error occurs.
+
+
+
+
+
+
+
+
+readNBytes
+public static byte[] readNBytes(java.io.InputStream in,
+ int len)
+ throws java.io.IOException
+Reads from the given input stream an amount of bytes and retrieves these data as an array of bytes.
+
+ The method is blocking !
+
+Parameters:
+in
- The input stream where to read the data coming from.
+len
- The amount of data to read
+Returns:
+The read data as an array of bytes
.
+Throws:
+java.io.IOException
- If the first byte cannot be read for any reason other
+ than the end of the file, if the input stream has been
+ closed, or if some other I/O error occurs.
+
+
+
+
+
+
+
+
+readLine
+public static byte[] readLine(java.io.InputStream in)
+ throws java.io.IOException
+Reads a line of text. A line is considered to be terminated by any one of a
+ line feed ('\n'), a carriage return ('\r'), or a carriage return followed
+ immediately by a line feed.
+
+Parameters:
+in
- The Input Stream to read from.
+Returns:
+An array of bytes containing the contents of the line, not including any
+ line-termination characters, or null if the end of the stream has
+ been reached.
+Throws:
+java.io.IOException
- If an I/O error occurs
+
+
+
+
+
+
+
+
+writeLine
+public static void writeLine(java.io.OutputStream out,
+ byte[] toSend)
+ throws java.io.IOException
+Send the data contained in the given array of bytes through the output
+ stream. If the data to send do not end with a carriage return, the method adds '\r\n' at the end.
+
+Parameters:
+out
- The Output Stream to send the data to.
+toSend
- The data to send
+Throws:
+java.io.IOException
- If an I/O error occurs
+
+
+
+
+
+
+
+
+sendBytes
+public static void sendBytes(java.io.OutputStream out,
+ byte[] toSend,
+ int offset,
+ int length)
+ throws java.io.IOException
+This method sends the content of the buffer
to the given OutputStream
. This content is
+ specified by the starting position, defined by offset
, and the amount of bytes,defined by
+ length
. If an error occurs during this process, a exception will be raised.
+
+Parameters:
+out
- The Output Stream to send the data to.
+toSend
- The data to send
+offset
- The starting position in the buffer of data
+length
- The amount of bytes to be sent.
+Throws:
+java.io.IOException
- If an I/O error occurs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+bytesToFloat
+public static java.lang.Float bytesToFloat(byte[] bytes,
+ int offset,
+ int size)
+Returns a float
value from array of bytes. This byte's array can only be 2 or 4 bytes long.
+
+Parameters:
+bytes
- The array of bytes to convert.
+offset
- The position where the method has to start to get the bytes from.
+size
- The amount of bytes to convert.
+Returns:
+A Float
value or null
if the process failed.
+
+
+
+
+
+
+
+
+fileParser
+public static java.io.BufferedReader fileParser(java.lang.String path,
+ java.lang.String fileName)
+Method to use to access a file in your resources folder... The file you want to access has to be under the
+ `resources` folder of your project. You can create as many sub-folders as you want, they will become the path of
+ the file to work with. This path is given to the method by the parameter `path` and the file is identified by its
+ name and extension.
+
+Parameters:
+path
- folder's hierarchy (if exists) from `resources`
+fileName
- Name of the file to access
+Returns:
+A BufferedReader
related to the file you want to work with, or null if the file could not
+ be reached.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Prev Class
+Next Class
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/ch/hevs/isi/utils/package-frame.html b/javadoc/hei/ch/hevs/isi/utils/package-frame.html
new file mode 100644
index 0000000..0568683
--- /dev/null
+++ b/javadoc/hei/ch/hevs/isi/utils/package-frame.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+ch.hevs.isi.utils
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/ch/hevs/isi/utils/package-summary.html b/javadoc/hei/ch/hevs/isi/utils/package-summary.html
new file mode 100644
index 0000000..1a39716
--- /dev/null
+++ b/javadoc/hei/ch/hevs/isi/utils/package-summary.html
@@ -0,0 +1,140 @@
+
+
+
+
+
+ch.hevs.isi.utils
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+Prev Package
+Next Package
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Class Summary
+
+Class
+Description
+
+
+
+Utility
+
+This class contains some useful Java methods to manipulate data.
+
+
+
+
+
+
+
+
+
+
+
+Prev Package
+Next Package
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/ch/hevs/isi/utils/package-tree.html b/javadoc/hei/ch/hevs/isi/utils/package-tree.html
new file mode 100644
index 0000000..e516cb3
--- /dev/null
+++ b/javadoc/hei/ch/hevs/isi/utils/package-tree.html
@@ -0,0 +1,129 @@
+
+
+
+
+
+ch.hevs.isi.utils Class Hierarchy
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/constant-values.html b/javadoc/hei/constant-values.html
new file mode 100644
index 0000000..f2aca1f
--- /dev/null
+++ b/javadoc/hei/constant-values.html
@@ -0,0 +1,149 @@
+
+
+
+
+
+Constant Field Values
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
ch.hevs.*
+
+
+
+ch.hevs.isi.utils.Utility
+
+Modifier and Type
+Constant Field
+Value
+
+
+
+
+
+ public static final int
+TCP_BUFFER_SIZE
+4096
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/deprecated-list.html b/javadoc/hei/deprecated-list.html
new file mode 100644
index 0000000..ee4f2b6
--- /dev/null
+++ b/javadoc/hei/deprecated-list.html
@@ -0,0 +1,120 @@
+
+
+
+
+
+Deprecated List
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/help-doc.html b/javadoc/hei/help-doc.html
new file mode 100644
index 0000000..bcc094f
--- /dev/null
+++ b/javadoc/hei/help-doc.html
@@ -0,0 +1,217 @@
+
+
+
+
+
+API Help
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+Package
+Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:
+
+Interfaces (italic)
+Classes
+Enums
+Exceptions
+Errors
+Annotation Types
+
+
+
+Class/Interface
+Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+
+Class inheritance diagram
+Direct Subclasses
+All Known Subinterfaces
+All Known Implementing Classes
+Class/interface declaration
+Class/interface description
+
+
+Nested Class Summary
+Field Summary
+Constructor Summary
+Method Summary
+
+
+Field Detail
+Constructor Detail
+Method Detail
+
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
+
+
+Annotation Type
+Each annotation type has its own separate page with the following sections:
+
+Annotation Type declaration
+Annotation Type description
+Required Element Summary
+Optional Element Summary
+Element Detail
+
+
+
+Enum
+Each enum has its own separate page with the following sections:
+
+Enum declaration
+Enum description
+Enum Constant Summary
+Enum Constant Detail
+
+
+
+Tree (Class Hierarchy)
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object
. The interfaces do not inherit from java.lang.Object
.
+
+When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
+When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
+
+
+
+Deprecated API
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
+
+
+Index
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
+
+
+Prev/Next
+These links take you to the next or previous class, interface, package, or related page.
+
+
+Frames/No Frames
+These links show and hide the HTML frames. All pages are available with or without frames.
+
+
+All Classes
+The All Classes link shows all classes and interfaces except non-static nested types.
+
+
+Serialized Form
+Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
+
+
+Constant Field Values
+The Constant Field Values page lists the static final fields and their values.
+
+
+
This help file applies to API documentation generated using the standard doclet.
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-1.html b/javadoc/hei/index-files/index-1.html
new file mode 100644
index 0000000..58c2f0e
--- /dev/null
+++ b/javadoc/hei/index-files/index-1.html
@@ -0,0 +1,127 @@
+
+
+
+
+
+B-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
B
+
+bytesToFloat(byte[], int, int) - Static method in class ch.hevs.isi.utils.Utility
+
+Returns a float
value from array of bytes.
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-10.html b/javadoc/hei/index-files/index-10.html
new file mode 100644
index 0000000..1a576fa
--- /dev/null
+++ b/javadoc/hei/index-files/index-10.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+U-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
U
+
+unsignedByteToSignedInt(byte) - Static method in class ch.hevs.isi.utils.Utility
+
+Converts an unsigned byte to a signed integer.
+
+Utility - Class in ch.hevs.isi.utils
+
+This class contains some useful Java methods to manipulate data.
+
+Utility() - Constructor for class ch.hevs.isi.utils.Utility
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-11.html b/javadoc/hei/index-files/index-11.html
new file mode 100644
index 0000000..3f6c650
--- /dev/null
+++ b/javadoc/hei/index-files/index-11.html
@@ -0,0 +1,132 @@
+
+
+
+
+
+W-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
W
+
+waitSomeTime(int) - Static method in class ch.hevs.isi.utils.Utility
+
+To wait some times ...
+
+writeLine(OutputStream, byte[]) - Static method in class ch.hevs.isi.utils.Utility
+
+Send the data contained in the given array of bytes through the output
+ stream.
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-2.html b/javadoc/hei/index-files/index-2.html
new file mode 100644
index 0000000..f9507e0
--- /dev/null
+++ b/javadoc/hei/index-files/index-2.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+C-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
C
+
+calculateCRC(byte[], int, int) - Static method in class ch.hevs.isi.utils.Utility
+
+Calculates and returns the CRC using the data passed in parameters.
+
+ch.hevs.isi.utils - package ch.hevs.isi.utils
+
+checkCRC(byte[], int, int, byte[]) - Static method in class ch.hevs.isi.utils.Utility
+
+Checks the CRC and returns true if it is correct, otherwise false.
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-3.html b/javadoc/hei/index-files/index-3.html
new file mode 100644
index 0000000..c56dcfc
--- /dev/null
+++ b/javadoc/hei/index-files/index-3.html
@@ -0,0 +1,125 @@
+
+
+
+
+
+D-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
D
+
+DEBUG(String, String, String) - Static method in class ch.hevs.isi.utils.Utility
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-4.html b/javadoc/hei/index-files/index-4.html
new file mode 100644
index 0000000..7a920bd
--- /dev/null
+++ b/javadoc/hei/index-files/index-4.html
@@ -0,0 +1,127 @@
+
+
+
+
+
+F-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
F
+
+fileParser(String, String) - Static method in class ch.hevs.isi.utils.Utility
+
+Method to use to access a file in your resources folder...
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-5.html b/javadoc/hei/index-files/index-5.html
new file mode 100644
index 0000000..80d5d83
--- /dev/null
+++ b/javadoc/hei/index-files/index-5.html
@@ -0,0 +1,135 @@
+
+
+
+
+
+G-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
G
+
+getHexString(byte[]) - Static method in class ch.hevs.isi.utils.Utility
+
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f).
+
+getHexString(byte[], int, int) - Static method in class ch.hevs.isi.utils.Utility
+
+Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+
+getStringRndVal(int) - Static method in class ch.hevs.isi.utils.Utility
+
+Retrieves a random value rounded to 2 decimal...
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-6.html b/javadoc/hei/index-files/index-6.html
new file mode 100644
index 0000000..ba120dc
--- /dev/null
+++ b/javadoc/hei/index-files/index-6.html
@@ -0,0 +1,127 @@
+
+
+
+
+
+M-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
M
+
+md5sum(String) - Static method in class ch.hevs.isi.utils.Utility
+
+Returns the md5 of any input...
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-7.html b/javadoc/hei/index-files/index-7.html
new file mode 100644
index 0000000..f07afd2
--- /dev/null
+++ b/javadoc/hei/index-files/index-7.html
@@ -0,0 +1,140 @@
+
+
+
+
+
+R-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
R
+
+readBytes(InputStream) - Static method in class ch.hevs.isi.utils.Utility
+
+Reads the incoming data from an input stream as long as there is something to read and saved the data in an array
+ of bytes.
+
+readLine(InputStream) - Static method in class ch.hevs.isi.utils.Utility
+
+Reads a line of text.
+
+readNBytes(InputStream, int) - Static method in class ch.hevs.isi.utils.Utility
+
+Reads from the given input stream an amount of bytes and retrieves these data as an array of bytes.
+
+rnd - Static variable in class ch.hevs.isi.utils.Utility
+
+Object to get some random values...
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-8.html b/javadoc/hei/index-files/index-8.html
new file mode 100644
index 0000000..7140eb4
--- /dev/null
+++ b/javadoc/hei/index-files/index-8.html
@@ -0,0 +1,127 @@
+
+
+
+
+
+S-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
S
+
+sendBytes(OutputStream, byte[], int, int) - Static method in class ch.hevs.isi.utils.Utility
+
+This method sends the content of the buffer
to the given OutputStream
.
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index-files/index-9.html b/javadoc/hei/index-files/index-9.html
new file mode 100644
index 0000000..9e482e4
--- /dev/null
+++ b/javadoc/hei/index-files/index-9.html
@@ -0,0 +1,127 @@
+
+
+
+
+
+T-Index
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+B C D F G M R S T U W
+
+
+
T
+
+TCP_BUFFER_SIZE - Static variable in class ch.hevs.isi.utils.Utility
+
+Default size for the TCP input stream
+
+
+
B C D F G M R S T U W
+
+
+
+
+
+
diff --git a/javadoc/hei/index.html b/javadoc/hei/index.html
new file mode 100644
index 0000000..6d16581
--- /dev/null
+++ b/javadoc/hei/index.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+Generated Documentation (Untitled)
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+Frame Alert
+This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
+
+
+
diff --git a/javadoc/hei/overview-tree.html b/javadoc/hei/overview-tree.html
new file mode 100644
index 0000000..3a74838
--- /dev/null
+++ b/javadoc/hei/overview-tree.html
@@ -0,0 +1,133 @@
+
+
+
+
+
+Class Hierarchy
+
+
+
+
+
+
+
+JavaScript is disabled on your browser.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/javadoc/hei/package-list b/javadoc/hei/package-list
new file mode 100644
index 0000000..b70d89b
--- /dev/null
+++ b/javadoc/hei/package-list
@@ -0,0 +1 @@
+ch.hevs.isi.utils
diff --git a/javadoc/hei/script.js b/javadoc/hei/script.js
new file mode 100644
index 0000000..b346356
--- /dev/null
+++ b/javadoc/hei/script.js
@@ -0,0 +1,30 @@
+function show(type)
+{
+ count = 0;
+ for (var key in methods) {
+ var row = document.getElementById(key);
+ if ((methods[key] & type) != 0) {
+ row.style.display = '';
+ row.className = (count++ % 2) ? rowColor : altColor;
+ }
+ else
+ row.style.display = 'none';
+ }
+ updateTabs(type);
+}
+
+function updateTabs(type)
+{
+ for (var value in tabs) {
+ var sNode = document.getElementById(tabs[value][0]);
+ var spanNode = sNode.firstChild;
+ if (value == type) {
+ sNode.className = activeTableTab;
+ spanNode.innerHTML = tabs[value][1];
+ }
+ else {
+ sNode.className = tableTab;
+ spanNode.innerHTML = "" + tabs[value][1] + " ";
+ }
+ }
+}
diff --git a/javadoc/hei/stylesheet.css b/javadoc/hei/stylesheet.css
new file mode 100644
index 0000000..98055b2
--- /dev/null
+++ b/javadoc/hei/stylesheet.css
@@ -0,0 +1,574 @@
+/* Javadoc style sheet */
+/*
+Overall document style
+*/
+
+@import url('resources/fonts/dejavu.css');
+
+body {
+ background-color:#ffffff;
+ color:#353833;
+ font-family:'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size:14px;
+ margin:0;
+}
+a:link, a:visited {
+ text-decoration:none;
+ color:#4A6782;
+}
+a:hover, a:focus {
+ text-decoration:none;
+ color:#bb7a2a;
+}
+a:active {
+ text-decoration:none;
+ color:#4A6782;
+}
+a[name] {
+ color:#353833;
+}
+a[name]:hover {
+ text-decoration:none;
+ color:#353833;
+}
+pre {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+}
+h1 {
+ font-size:20px;
+}
+h2 {
+ font-size:18px;
+}
+h3 {
+ font-size:16px;
+ font-style:italic;
+}
+h4 {
+ font-size:13px;
+}
+h5 {
+ font-size:12px;
+}
+h6 {
+ font-size:11px;
+}
+ul {
+ list-style-type:disc;
+}
+code, tt {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ padding-top:4px;
+ margin-top:8px;
+ line-height:1.4em;
+}
+dt code {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ padding-top:4px;
+}
+table tr td dt code {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ vertical-align:top;
+ padding-top:4px;
+}
+sup {
+ font-size:8px;
+}
+/*
+Document title and Copyright styles
+*/
+.clear {
+ clear:both;
+ height:0px;
+ overflow:hidden;
+}
+.aboutLanguage {
+ float:right;
+ padding:0px 21px;
+ font-size:11px;
+ z-index:200;
+ margin-top:-9px;
+}
+.legalCopy {
+ margin-left:.5em;
+}
+.bar a, .bar a:link, .bar a:visited, .bar a:active {
+ color:#FFFFFF;
+ text-decoration:none;
+}
+.bar a:hover, .bar a:focus {
+ color:#bb7a2a;
+}
+.tab {
+ background-color:#0066FF;
+ color:#ffffff;
+ padding:8px;
+ width:5em;
+ font-weight:bold;
+}
+/*
+Navigation bar styles
+*/
+.bar {
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ padding:.8em .5em .4em .8em;
+ height:auto;/*height:1.8em;*/
+ font-size:11px;
+ margin:0;
+}
+.topNav {
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ float:left;
+ padding:0;
+ width:100%;
+ clear:right;
+ height:2.8em;
+ padding-top:10px;
+ overflow:hidden;
+ font-size:12px;
+}
+.bottomNav {
+ margin-top:10px;
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ float:left;
+ padding:0;
+ width:100%;
+ clear:right;
+ height:2.8em;
+ padding-top:10px;
+ overflow:hidden;
+ font-size:12px;
+}
+.subNav {
+ background-color:#dee3e9;
+ float:left;
+ width:100%;
+ overflow:hidden;
+ font-size:12px;
+}
+.subNav div {
+ clear:left;
+ float:left;
+ padding:0 0 5px 6px;
+ text-transform:uppercase;
+}
+ul.navList, ul.subNavList {
+ float:left;
+ margin:0 25px 0 0;
+ padding:0;
+}
+ul.navList li{
+ list-style:none;
+ float:left;
+ padding: 5px 6px;
+ text-transform:uppercase;
+}
+ul.subNavList li{
+ list-style:none;
+ float:left;
+}
+.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited {
+ color:#FFFFFF;
+ text-decoration:none;
+ text-transform:uppercase;
+}
+.topNav a:hover, .bottomNav a:hover {
+ text-decoration:none;
+ color:#bb7a2a;
+ text-transform:uppercase;
+}
+.navBarCell1Rev {
+ background-color:#F8981D;
+ color:#253441;
+ margin: auto 5px;
+}
+.skipNav {
+ position:absolute;
+ top:auto;
+ left:-9999px;
+ overflow:hidden;
+}
+/*
+Page header and footer styles
+*/
+.header, .footer {
+ clear:both;
+ margin:0 20px;
+ padding:5px 0 0 0;
+}
+.indexHeader {
+ margin:10px;
+ position:relative;
+}
+.indexHeader span{
+ margin-right:15px;
+}
+.indexHeader h1 {
+ font-size:13px;
+}
+.title {
+ color:#2c4557;
+ margin:10px 0;
+}
+.subTitle {
+ margin:5px 0 0 0;
+}
+.header ul {
+ margin:0 0 15px 0;
+ padding:0;
+}
+.footer ul {
+ margin:20px 0 5px 0;
+}
+.header ul li, .footer ul li {
+ list-style:none;
+ font-size:13px;
+}
+/*
+Heading styles
+*/
+div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
+ background-color:#dee3e9;
+ border:1px solid #d0d9e0;
+ margin:0 0 6px -8px;
+ padding:7px 5px;
+}
+ul.blockList ul.blockList ul.blockList li.blockList h3 {
+ background-color:#dee3e9;
+ border:1px solid #d0d9e0;
+ margin:0 0 6px -8px;
+ padding:7px 5px;
+}
+ul.blockList ul.blockList li.blockList h3 {
+ padding:0;
+ margin:15px 0;
+}
+ul.blockList li.blockList h2 {
+ padding:0px 0 20px 0;
+}
+/*
+Page layout container styles
+*/
+.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer {
+ clear:both;
+ padding:10px 20px;
+ position:relative;
+}
+.indexContainer {
+ margin:10px;
+ position:relative;
+ font-size:12px;
+}
+.indexContainer h2 {
+ font-size:13px;
+ padding:0 0 3px 0;
+}
+.indexContainer ul {
+ margin:0;
+ padding:0;
+}
+.indexContainer ul li {
+ list-style:none;
+ padding-top:2px;
+}
+.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt {
+ font-size:12px;
+ font-weight:bold;
+ margin:10px 0 0 0;
+ color:#4E4E4E;
+}
+.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd {
+ margin:5px 0 10px 0px;
+ font-size:14px;
+ font-family:'DejaVu Sans Mono',monospace;
+}
+.serializedFormContainer dl.nameValue dt {
+ margin-left:1px;
+ font-size:1.1em;
+ display:inline;
+ font-weight:bold;
+}
+.serializedFormContainer dl.nameValue dd {
+ margin:0 0 0 1px;
+ font-size:1.1em;
+ display:inline;
+}
+/*
+List styles
+*/
+ul.horizontal li {
+ display:inline;
+ font-size:0.9em;
+}
+ul.inheritance {
+ margin:0;
+ padding:0;
+}
+ul.inheritance li {
+ display:inline;
+ list-style:none;
+}
+ul.inheritance li ul.inheritance {
+ margin-left:15px;
+ padding-left:15px;
+ padding-top:1px;
+}
+ul.blockList, ul.blockListLast {
+ margin:10px 0 10px 0;
+ padding:0;
+}
+ul.blockList li.blockList, ul.blockListLast li.blockList {
+ list-style:none;
+ margin-bottom:15px;
+ line-height:1.4;
+}
+ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList {
+ padding:0px 20px 5px 10px;
+ border:1px solid #ededed;
+ background-color:#f8f8f8;
+}
+ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList {
+ padding:0 0 5px 8px;
+ background-color:#ffffff;
+ border:none;
+}
+ul.blockList ul.blockList ul.blockList ul.blockList li.blockList {
+ margin-left:0;
+ padding-left:0;
+ padding-bottom:15px;
+ border:none;
+}
+ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast {
+ list-style:none;
+ border-bottom:none;
+ padding-bottom:0;
+}
+table tr td dl, table tr td dl dt, table tr td dl dd {
+ margin-top:0;
+ margin-bottom:1px;
+}
+/*
+Table styles
+*/
+.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary {
+ width:100%;
+ border-left:1px solid #EEE;
+ border-right:1px solid #EEE;
+ border-bottom:1px solid #EEE;
+}
+.overviewSummary, .memberSummary {
+ padding:0px;
+}
+.overviewSummary caption, .memberSummary caption, .typeSummary caption,
+.useSummary caption, .constantsSummary caption, .deprecatedSummary caption {
+ position:relative;
+ text-align:left;
+ background-repeat:no-repeat;
+ color:#253441;
+ font-weight:bold;
+ clear:none;
+ overflow:hidden;
+ padding:0px;
+ padding-top:10px;
+ padding-left:1px;
+ margin:0px;
+ white-space:pre;
+}
+.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link,
+.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link,
+.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover,
+.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover,
+.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active,
+.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active,
+.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited,
+.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited {
+ color:#FFFFFF;
+}
+.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span,
+.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ padding-bottom:7px;
+ display:inline-block;
+ float:left;
+ background-color:#F8981D;
+ border: none;
+ height:16px;
+}
+.memberSummary caption span.activeTableTab span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ margin-right:3px;
+ display:inline-block;
+ float:left;
+ background-color:#F8981D;
+ height:16px;
+}
+.memberSummary caption span.tableTab span {
+ white-space:nowrap;
+ padding-top:5px;
+ padding-left:12px;
+ padding-right:12px;
+ margin-right:3px;
+ display:inline-block;
+ float:left;
+ background-color:#4D7A97;
+ height:16px;
+}
+.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab {
+ padding-top:0px;
+ padding-left:0px;
+ padding-right:0px;
+ background-image:none;
+ float:none;
+ display:inline;
+}
+.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd,
+.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd {
+ display:none;
+ width:5px;
+ position:relative;
+ float:left;
+ background-color:#F8981D;
+}
+.memberSummary .activeTableTab .tabEnd {
+ display:none;
+ width:5px;
+ margin-right:3px;
+ position:relative;
+ float:left;
+ background-color:#F8981D;
+}
+.memberSummary .tableTab .tabEnd {
+ display:none;
+ width:5px;
+ margin-right:3px;
+ position:relative;
+ background-color:#4D7A97;
+ float:left;
+
+}
+.overviewSummary td, .memberSummary td, .typeSummary td,
+.useSummary td, .constantsSummary td, .deprecatedSummary td {
+ text-align:left;
+ padding:0px 0px 12px 10px;
+}
+th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th,
+td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{
+ vertical-align:top;
+ padding-right:0px;
+ padding-top:8px;
+ padding-bottom:3px;
+}
+th.colFirst, th.colLast, th.colOne, .constantsSummary th {
+ background:#dee3e9;
+ text-align:left;
+ padding:8px 3px 3px 7px;
+}
+td.colFirst, th.colFirst {
+ white-space:nowrap;
+ font-size:13px;
+}
+td.colLast, th.colLast {
+ font-size:13px;
+}
+td.colOne, th.colOne {
+ font-size:13px;
+}
+.overviewSummary td.colFirst, .overviewSummary th.colFirst,
+.useSummary td.colFirst, .useSummary th.colFirst,
+.overviewSummary td.colOne, .overviewSummary th.colOne,
+.memberSummary td.colFirst, .memberSummary th.colFirst,
+.memberSummary td.colOne, .memberSummary th.colOne,
+.typeSummary td.colFirst{
+ width:25%;
+ vertical-align:top;
+}
+td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover {
+ font-weight:bold;
+}
+.tableSubHeadingColor {
+ background-color:#EEEEFF;
+}
+.altColor {
+ background-color:#FFFFFF;
+}
+.rowColor {
+ background-color:#EEEEEF;
+}
+/*
+Content styles
+*/
+.description pre {
+ margin-top:0;
+}
+.deprecatedContent {
+ margin:0;
+ padding:10px 0;
+}
+.docSummary {
+ padding:0;
+}
+
+ul.blockList ul.blockList ul.blockList li.blockList h3 {
+ font-style:normal;
+}
+
+div.block {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+}
+
+td.colLast div {
+ padding-top:0px;
+}
+
+
+td.colLast a {
+ padding-bottom:3px;
+}
+/*
+Formatting effect styles
+*/
+.sourceLineNo {
+ color:green;
+ padding:0 30px 0 0;
+}
+h1.hidden {
+ visibility:hidden;
+ overflow:hidden;
+ font-size:10px;
+}
+.block {
+ display:block;
+ margin:3px 10px 2px 0px;
+ color:#474747;
+}
+.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink,
+.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel,
+.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink {
+ font-weight:bold;
+}
+.deprecationComment, .emphasizedPhrase, .interfaceName {
+ font-style:italic;
+}
+
+div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase,
+div.block div.block span.interfaceName {
+ font-style:normal;
+}
+
+div.contentContainer ul.blockList li.blockList h2{
+ padding-bottom:0px;
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..82220a5
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,63 @@
+
+
+ 4.0.0
+
+ MineCraft
+ HEI
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+
+
+
+
+ false
+
+
+ true
+
+ ias-snapshots
+ Infinite Automation Snapshot Repository
+ https://maven.mangoautomation.net/repository/ias-snapshot/
+
+
+
+ true
+
+
+ false
+
+ ias-releases
+ Infinite Automation Release Repository
+ https://maven.mangoautomation.net/repository/ias-release/
+
+
+
+
+
+ com.infiniteautomation
+ modbus4j
+ 3.0.4
+
+
+
+
+ org.java-websocket
+ Java-WebSocket
+ 1.5.2
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java
new file mode 100644
index 0000000..ed7bb59
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/MinecraftController.java
@@ -0,0 +1,78 @@
+package ch.hevs.isi;
+
+import ch.hevs.isi.utils.Utility;
+
+public class MinecraftController {
+
+ public static boolean ERASE_PREVIOUS_DATA_INB_DB = false;
+
+ public static void usage() {
+ System.out.println();
+ System.out.println("You're reading this message because no parameter (or not the needed ones) has been passed to the application.");
+ System.out.println();
+ System.out.println("In development mode, just add to your running configuration the needed parameters (see usage below).");
+ System.out.println("In running mode, the application's usage is the following:");
+ System.out.println("java MinecraftController [-modbus4j] [-keepAlive]");
+ System.out.println("where:");
+ System.out.println("- : The complete URL of the InfluxDB server, including the protocol (http or https)...");
+ System.out.println(" Example: https://influx.sdi.hevs.ch");
+ System.out.println("- : The name of the Influx DB to use. For this project, this name is the name of the group you've been affected to. (SInXX)");
+ System.out.println("- : The IP address of the Minecraft ModbusTCP server (default value: localhost)");
+ System.out.println("- : The port number of the Minecraft ModbusTCP server (default value: 1502)");
+ System.out.println("- [-eraseDB]: Optional parameter! If set, the application will erase the previous data in InfluxDB...");
+ System.out.println();
+ System.exit(1);
+ }
+
+ @SuppressWarnings("all")
+ public static void main(String[] args) {
+
+ // ------------------------------------- DO NOT CHANGE THE FOLLOWING LINES -------------------------------------
+ String dbProtocol = "http";
+ String dbHostName = "localhost";
+ String dbName = "labo";
+ String dbUserName = "root";
+ String dbPassword = "root";
+
+ String modbusTcpHost = "localhost";
+ int modbusTcpPort = 1502;
+
+ // Check the number of arguments and show usage message if the number does not match.
+ String[] parameters = null;
+
+ // If there is only one number given as parameter, construct the parameters according the group number.
+ if (args.length >= 5) {
+ parameters = args;
+
+ // Decode parameters for influxDB
+ String[] dbParams = parameters[0].split("://");
+ if (dbParams.length != 2) {
+ usage();
+ }
+
+ dbProtocol = dbParams[0];
+ dbHostName = dbParams[1];
+ dbName = parameters[1];
+ dbUserName = parameters[2];
+ dbPassword = Utility.md5sum(dbUserName);
+
+ // Decode parameters for Modbus TCP
+ modbusTcpHost = parameters[3];
+ modbusTcpPort = Integer.parseInt(parameters[4]);
+
+ for (int i = 5; i < args.length; i++) {
+ if (parameters[i].compareToIgnoreCase("-erasedb") == 0) {
+ ERASE_PREVIOUS_DATA_INB_DB = true;
+ }
+ }
+ } else {
+ usage();
+ }
+
+ // ------------------------------------ /DO NOT CHANGE THE FOLLOWING LINES -------------------------------------
+
+ // Start coding here ...
+
+ }
+}
diff --git a/src/main/java/ch/hevs/isi/core/package-info.java b/src/main/java/ch/hevs/isi/core/package-info.java
new file mode 100644
index 0000000..800e3c8
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/core/package-info.java
@@ -0,0 +1 @@
+package ch.hevs.isi.core;
\ No newline at end of file
diff --git a/src/main/java/ch/hevs/isi/db/TimeManager.java b/src/main/java/ch/hevs/isi/db/TimeManager.java
new file mode 100644
index 0000000..ca1ae96
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/db/TimeManager.java
@@ -0,0 +1,113 @@
+package ch.hevs.isi.db;
+
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * TimeManager Class
+ *
+ * This class allows to calculate a timestamp taking into account the time index of Minecraft Electrical Age and its
+ * time acceleration. (1 day = 10 minutes)
+ * You also have to indicate a number of days to subtract from the current time which will determine the time t0 which
+ * defines the starting time of the simulation.
+ */
+public class TimeManager {
+
+ // Start time
+ private final LocalDateTime t0;
+
+ // days since beginning of game
+ private long days;
+
+ // previous value of "CLOCK_FLOAT" coming from Minecraft EA
+ private float lastEaClock;
+
+ // timestamp for InfluxDB
+ private long nanosForDB;
+
+
+ /* ************************************************************************************************************ */
+ /* Constructors */
+ /* ************************************************************************************************************ */
+ /**
+ * Constructor of TimeManager class, where the start time of the game is calculated from today at midnight minus
+ * the given number of days. Today at midnight, from local time.
+ *
+ * @param minusDays The number of days to subtract to the current day.
+ */
+ public TimeManager(int minusDays) {
+ t0 = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(minusDays);
+ days = 0;
+ lastEaClock = 0f;
+ nanosForDB = 0;
+ }
+
+
+ /* ************************************************************************************************************ */
+ /* Public methods */
+ /* ************************************************************************************************************ */
+ /**
+ * This method takes the index of the Electrical-Age clock and generates the corresponding timestamp.
+ *
+ * @param strEaClock The EA clock given as a {@code String}
+ */
+ public void setTimestamp(String strEaClock) {
+ setTimestamp(Float.parseFloat(strEaClock));
+ }
+
+ /**
+ * This method takes the index of the Electrical-Age clock and generates the corresponding timestamp.
+ *
+ * @param eaClock The EA clock given as a {@code float}
+ */
+ public void setTimestamp(float eaClock) {
+ // eaClock: value read in data point with label "CLOCK_FLOAT", if it's less then the previous one, it means
+ // that a day has passed !
+ if (eaClock < lastEaClock)
+ days++;
+
+ // Storing the EA Clock and computing the corresponding nanoseconds...
+ lastEaClock = eaClock;
+ long nanoOfDay = Math.round(eaClock * (24 * 3600E9));
+
+ // Creates a timestamp from t0 and adding to it the passed days and the nanoseconds of the current days
+ LocalDateTime tInsert = t0.plusDays(days);
+ tInsert = tInsert.plus(Duration.ofNanos(nanoOfDay));
+ System.out.println("tInsert in method: " + tInsert.format(DateTimeFormatter.ISO_DATE_TIME));
+
+ // Getting the related timestamp in nanoseconds according to the local time zone
+ ZoneId zoneId = ZoneId.systemDefault();
+ nanosForDB = tInsert.atZone(zoneId).toEpochSecond() * 1000000000;
+ }
+
+ /**
+ * Gives the actual timestamp according to the EA clock.
+ *
+ * @return The timestamp in nanoseconds
+ */
+ public long getNanosForDB() {
+ return nanosForDB; // nanos for writing in DB
+ }
+
+ /**
+ * Returns {@code true}
+ * @return
+ */
+ public boolean isLastDay() {
+ return (days % 3) == 2;
+ }
+
+ /* ************************************************************************************************************ */
+ /* */
+ /* Public Main */
+ /* */
+ /* ************************************************************************************************************ */
+ public static void main(String[] args) {
+ TimeManager tm = new TimeManager(3);
+ System.out.println("t0: " + tm.t0.toString());
+ tm.setTimestamp(0.5f);
+ System.out.println("nanosForDBs: " + tm.getNanosForDB());
+ tm.setTimestamp("0.1");
+ System.out.println("nanosForDBs: " + tm.getNanosForDB());
+ }
+}
diff --git a/src/main/java/ch/hevs/isi/db/package-info.java b/src/main/java/ch/hevs/isi/db/package-info.java
new file mode 100644
index 0000000..22bf990
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/db/package-info.java
@@ -0,0 +1 @@
+package ch.hevs.isi.db;
\ No newline at end of file
diff --git a/src/main/java/ch/hevs/isi/field/package-info.java b/src/main/java/ch/hevs/isi/field/package-info.java
new file mode 100644
index 0000000..401a207
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/field/package-info.java
@@ -0,0 +1 @@
+package ch.hevs.isi.field;
\ No newline at end of file
diff --git a/src/main/java/ch/hevs/isi/utils/Utility.java b/src/main/java/ch/hevs/isi/utils/Utility.java
new file mode 100644
index 0000000..9edfd89
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/utils/Utility.java
@@ -0,0 +1,422 @@
+package ch.hevs.isi.utils;
+
+
+import java.io.*;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * This class contains some useful Java methods to manipulate Modbus data.
+ *
+ * @author Michael Clausen
+ * @author Cedric Crettaz
+ */
+@SuppressWarnings("unused")
+public class Utility {
+ /** Default size for the TCP input stream */
+ public static final int TCP_BUFFER_SIZE = 4096;
+
+ /** Object to get some random values... */
+ public static Random rnd = new Random(1);
+
+ /**
+ * Calculates and returns the CRC using the data passed in parameters.
+ *
+ * @param data a byte array containing the data to send
+ * @param offset the offset
+ * @param len the data length
+ * @return byte[] the CRC
+ */
+ public static byte[] calculateCRC(byte[] data , int offset , int len)
+ {
+ int crc = 0x0000FFFF;
+ for (int i = 0 ; i < len ; i++)
+ {
+ crc = crc ^ Utility.unsignedByteToSignedInt(data[i + offset]);
+ for (int j = 0 ; j < 8 ; j++)
+ {
+ int tmp = crc;
+ int carryFlag = tmp & 0x0001;
+ crc = crc >> 1;
+ if (carryFlag == 1)
+ {
+ crc = crc ^ 0xA001;
+ }
+ }
+ }
+
+ byte[] result = new byte[2];
+ result[0] = (byte)(crc & 0xFF);
+ result[1] = (byte)((crc & 0xFF00) >> 8);
+
+ return result;
+ }
+
+ /**
+ * Checks the CRC and returns true if it is correct, otherwise false.
+ *
+ * @param data a byte array containing the data to send
+ * @param offset the offset
+ * @param len the data length
+ * @param crc a byte array containing the CRC to check
+ * @return boolean true if the CRC is correct, otherwise false
+ */
+ public static boolean checkCRC(byte[] data , int offset , int len , byte[] crc)
+ {
+ byte[] calcCrc = Utility.calculateCRC(data , offset , len);
+ return (calcCrc[0] == crc[0] && calcCrc[1] == crc[1]);
+ }
+
+
+ /**
+ * Returns a float
value from array of bytes. This byte's array can only be 2 or 4 bytes long.
+ * @param bytes The array of bytes to convert.
+ * @param offset The position where the method has to start to get the bytes from.
+ * @param size The amount of bytes to convert.
+ * @return A Float
value or null
if the process failed.
+ */
+ public static Float bytesToFloat(byte[] bytes, int offset, int size) {
+
+ if (size == 2 || size == 4) {
+ byte[] tmp = new byte[4];
+ System.arraycopy(bytes, offset, tmp, 0, size);
+ try {
+ return ByteBuffer.wrap(tmp).order(ByteOrder.BIG_ENDIAN).getFloat();
+ } catch (Exception e) {
+ DEBUG("utils", "Utility", "bytesToFloat()", "ByteBufferException : " + e.getMessage());
+ }
+ } else {
+ DEBUG("utils", "Utility", "bytesToFloat()", "ERROR: size MUST be 2 or 4 !!!");
+ }
+ return null;
+ }
+
+ /**
+ * Converts an unsigned byte to a signed integer.
+ *
+ * @param from an unsigned byte to convert to a signed integer
+ * @return int a signed integer
+ */
+ public static int unsignedByteToSignedInt(byte from)
+ {
+ return 0x000000FF & (int)from;
+ }
+
+ /**
+ * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+ * @param b The array of bytes to be convert in HEX characters.
+ * @return A string representing the given array of byte in HEX values.
+ */
+ public static String getHexString(byte[] b) {
+ return getHexString(b, 0, b.length);
+ }
+
+ /**
+ * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f)
+ * @param b The byte array to convert in HEX string
+ * @param offset The index where we start to convert from.
+ * @param length The amount of bytes to convert in HEX string
+ * @return A String representing the HEX values of the selected bytes of the array.
+ */
+ public static String getHexString(byte[] b, int offset, int length) {
+ StringBuilder result = new StringBuilder();
+ for (int i = offset; i < offset+length; i++) {
+ result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
+ }
+ return result.toString();
+ }
+
+ /**
+ * Utility method to convert a byte array in a string made up of hex (0,.. 9, a,..f) and
+ * format the string with `0xCC` where CC is the string in HEX
+ * @param b The byte array to convert in HEX string
+ * @param offset The index where we start to convert from.
+ * @param length The amount of bytes to convert in HEX string
+ * @return A String representing the HEX values of the selected bytes of the array.
+ */
+ public static String getHexStringForDebug(byte[] b, int offset, int length) {
+ StringBuilder result = new StringBuilder();
+ for (int i = offset; i < offset+length; i++) {
+ result.append("0x");
+ result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
+ result.append(" ");
+ }
+ return result.toString().trim();
+ }
+
+
+ /**
+ * To be used to make a thread waiting for a certain amount of time
+ * @param thread The thread to be stopped
+ * @param millis The amount of time in [ms] to stop the thread.
+ */
+ public static void threadWait(Thread thread, long millis) {
+ try {
+ thread.wait(millis);
+ } catch(InterruptedException ie) {
+ DEBUG("utils", "Utility", "threadWait()", "InterruptedException : " + ie.getMessage());
+ } catch (NullPointerException npe) {
+ DEBUG("utils", "Utility", "threadWait()", "The given Thread is NULL !");
+ }
+ }
+
+ /**
+ * To wait some times ...
+ */
+ public static void waitSomeTime(int ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (InterruptedException e) {
+ DEBUG("utils", "Utility", "waitSomeTime()", "InterruptedException : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Returns the md5 of any input...
+ * @param msg The input string to process
+ * @return The md5 of the input string.
+ */
+ public static String md5sum(String msg)
+ {
+ try {
+ MessageDigest md = MessageDigest.getInstance("md5");
+ return String.format("%032x", new BigInteger(1, md.digest(msg.getBytes(StandardCharsets.UTF_8))));
+ } catch (NoSuchAlgorithmException e) {
+ DEBUG("utils", "Utility", "md5sum()", "NoSuchAlgorithmException : " + e.getMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Retrieves a random value rounded to 2 decimal...
+ *
+ * @param factor A coefficient which the random value is multiplied with.
+ * @return A random value rounded to 2 decimal converted to a String.
+ */
+ public static String getStringRndVal(int factor) {
+ float val = (float) rnd.nextDouble()*factor*10;
+ return String.format("%.2f", val).replace(",", ".");
+ }
+
+
+ /**
+ * Reads the incoming data from an input stream as long as there is
+ * something to read and saved the data in an array of bytes.
+ *
+ * The method is blocking !
+ * This method blocks until input data is available, end of file is detected,
+ * or an exception is thrown.
+ *
+ * If the length of of read data is zero, then no bytes are read and an empty
+ * array of bytes is returned; otherwise, there is an attempt to read at least
+ * one byte. If no byte is available because the stream is at the end of the
+ * file, the value -1 is returned; otherwise, at least one byte is read and
+ * returned as an array of bytes.
+ *
+ * @param in The input Stream where to read the data coming from.
+ * @return The read data as an array of bytes
. Or null if the
+ * has been closed by the peer while waiting for incoming data.
+ * @throws IOException If the first byte cannot be read for any reason other
+ * than the end of the file, if the input stream has been
+ * closed, or if some other I/O error occurs.
+ */
+ public static byte[] readBytes(InputStream in) throws IOException
+ {
+ byte[] buffer = new byte[TCP_BUFFER_SIZE];
+
+ // Read the incoming data
+ int b = in.read(buffer);
+
+ // Creates an array of bytes with the right size
+ if (b == -1) return null; // the connection has been canceled by the peer
+ else if (b == 0) return new byte[0]; // empty data
+ else { // The received data
+ byte[] rBytes = new byte[b];
+ System.arraycopy(buffer, 0, rBytes, 0, b);
+ return rBytes;
+ }
+ }
+
+ /**
+ * Reads from the given input stream an amount of bytes and retrieves these data as
+ * an array of bytes. This method is
+ *
+ * The method is blocking !
+ *
+ * @param in The input Stream where to read the data coming from.
+ * @param len The number of bytes to be read from the input stream.
+ *
+ * @return The read data as an array of bytes
.
+ *
+ * @throws IOException If the first byte cannot be read for any reason other
+ * than the end of the file, if the input stream has been
+ * closed, or if some other I/O error occurs.
+ */
+ public static byte[] readNBytes(InputStream in, int len) throws IOException
+ {
+ byte[] buffer = new byte[len];
+
+ // Checks that there is enough available data to read from the input stream
+ int counter = 0;
+ while (in.available() < len) {
+ Utility.waitSomeTime(2);
+ if (++counter > 10)
+ return null;
+ }
+
+ // Read the incoming data
+ int b = in.read(buffer, 0, len);
+
+ // Creates an array of bytes with the right size
+ if (b == -1) return null; // the connection has been canceled by the peer
+ else if (b == 0) return new byte[0]; // empty data
+ else return buffer; // The received data
+ }
+
+ /**
+ * Reads lines of text from the given input stream. A line is considered to be terminated by any one of a
+ * line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.
+ *
+ * @param in The Input Stream to read from.
+ * @return A list of String, without any line-termination characters, corresponding to each line read from the
+ * input stream, or an empty list if the end of the stream has been reached.
+ * @throws IOException If an I/O error occurs
+ */
+ public static List readLine(InputStream in) throws IOException {
+ List result = new LinkedList<>();
+
+ while (in.available() == 0) {
+ Utility.waitSomeTime(10);
+ }
+
+ while (in.available() != 0)
+ {
+ byte[] b = readBytes(in);
+
+ if (b != null && b.length > 0) {
+ String res = new String(b);
+ String[] l = null;
+ if (res.indexOf('\r') != -1) {
+ res = res.replace("\n", "");
+ l = res.split("\r");
+ } else if (res.indexOf('\n') != -1) {
+ res = res.replace("\r", "");
+ l = res.split("\n");
+ }
+
+ if (l != null) {
+ result.addAll(Arrays.asList(l));
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Send the data contained in the given array of bytes through the output
+ * stream. It raises an IOException if something goes wrong.
+ * The method returns the amount of bytes sent.
+ *
+ * @param out The Output Stream to send the data to.
+ * @param toSend The data to send
+ * @throws IOException If an I/O error occurs
+ */
+ public static void writeLine(OutputStream out, byte[] toSend) throws IOException {
+
+ if (toSend[toSend.length - 1] == '\n' || toSend[toSend.length - 1] == '\r')
+ out.write(toSend);
+ else {
+ byte[] temp = new byte[toSend.length + 2];
+ System.arraycopy(toSend, 0, temp, 0, toSend.length);
+ temp[temp.length - 2] = (byte) '\r';
+ temp[temp.length - 1] = (byte) '\n';
+ out.write(temp);
+ }
+
+ out.flush();
+ }
+
+ /**
+ * Method to use to access a file in your resources folder...
+ * @param pathName folder's name (if exists) from `resources`
+ * @param fileName Name of the file to access
+ *
+ * @return A BufferedReader related to the file you want to work with, or null if the file could not be reached.
+ */
+ public static BufferedReader fileParser(String pathName, String fileName) {
+ // set relative path
+ InputStream is;
+ if (pathName == null) {
+ is = ClassLoader.getSystemClassLoader().getResourceAsStream(fileName);
+ } else {
+ is = ClassLoader.getSystemClassLoader().getResourceAsStream(pathName + "/" + fileName);
+ }
+
+ if (is != null) {
+ return new BufferedReader(new InputStreamReader(is));
+ }
+ return null;
+ }
+
+
+ // DEBUG System.out
+ public static void DEBUG(String className, String method, String msg) {
+ DEBUG(null, className, method, msg);
+ }
+
+ public static void DEBUG(Object object, String method, String msg) {
+ String className = object.getClass().getSimpleName();
+ String[] packages = object.getClass().getPackage().getName().split("\\.");
+ if (packages.length > 1)
+ DEBUG(packages[packages.length-1], className, method, msg);
+ else if (packages.length == 1)
+ DEBUG(packages[0], className, method, msg);
+ else
+ DEBUG(null, className, method, msg);
+ }
+
+ public static void DEBUG(String packageName, String className, String method, String msg) {
+ final int nameLength = 25;
+ int millis = Calendar.getInstance().get(Calendar.MILLISECOND);
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
+
+ className = className.trim().replace("[", "").replace("]", "");
+ if (packageName != null)
+ className = packageName + ":" + className;
+
+ String cn = " [" + className + "] ";
+ StringBuilder logMsg = new StringBuilder();
+
+ // set the time
+ logMsg.append(sdf.format(Calendar.getInstance().getTime())).append(".").append(String.format("%3d", millis));
+
+ // Append Packages and ClassName
+ logMsg.append(cn);
+
+ // Append Method
+ StringBuilder met = new StringBuilder(method.trim().replace("(", "").replace(")", ""));
+ met.append("() > ");
+ while (met.length() < nameLength) {
+ met.append(" ");
+ }
+ logMsg.append(met);
+
+ // Append message if exists
+ if (msg != null) {
+ logMsg.append(msg);
+ }
+
+ if (logMsg.toString().endsWith("\n")) {
+ System.out.print(logMsg);
+ } else {
+ System.out.println(logMsg);
+ }
+ }
+}
diff --git a/src/main/java/ch/hevs/isi/web/package-info.java b/src/main/java/ch/hevs/isi/web/package-info.java
new file mode 100644
index 0000000..51a8dcc
--- /dev/null
+++ b/src/main/java/ch/hevs/isi/web/package-info.java
@@ -0,0 +1 @@
+package ch.hevs.isi.web;
\ No newline at end of file