Represents codes for the POSIX Systems baud rates and their real values
+ defined from invalid input: '<'./usr/include/x86_64-linux-gnu/bits/termios.h>.
An example for Serial4j showing Native terminal control and
+ native file io on a serial port using a java binding to invalid input: '<'fcntl.h> and invalid input: '<'unistd.h> read (...) and write (...).
Returns the enum constant of this class with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this class. (Extraneous whitespace characters are
+not permitted.)
+
+
Parameters:
+
name - the name of the enum constant to be returned.
Represents codes for the POSIX Systems baud rates and their real values
+ defined from invalid input: '<'./usr/include/x86_64-linux-gnu/bits/termios.h>.
+
+
+
+
+
+
+
Nested Class Summary
+
+
Nested classes/interfaces inherited from class java.lang.Enum
Returns the enum constant of this class with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this class. (Extraneous whitespace characters are
+not permitted.)
+
+
Parameters:
+
name - the name of the enum constant to be returned.
Gets the read configuration for this terminal device defining the timeout value as the first index and
+ the minimum number of read byte in this timeout as the second index.
Adjusts the read mode for this terminal device, the read mode is defined by the read timeout value and the minimum
+ number of bytes to read at that time.
Retrieves the terminal control flag from this terminal device port descriptor in 64-bit format.
+
+
Returns:
+
the [c_cflag] value in longs.
+
+
+
+
+
+
getTerminalLocalFlag
+
protectedlonggetTerminalLocalFlag()
+
Retrieves the terminal local flag from this terminal device port descriptor in 64-bit format.
+
+
Returns:
+
the [c_lflag] value in longs.
+
+
+
+
+
+
getTerminalInputFlag
+
protectedlonggetTerminalInputFlag()
+
Retrieves the terminal input flag from this terminal device port descriptor in 64-bit format.
+
+
Returns:
+
the [c_iflag] value in longs.
+
+
+
+
+
+
getTerminalOutputFlag
+
protectedlonggetTerminalOutputFlag()
+
Retrieves the terminal output flag from this terminal device port descriptor in 64-bit format.
+
+
Returns:
+
the [c_oflag] value in longs.
+
+
+
+
+
+
setReadConfigurationMode0
+
protectedintsetReadConfigurationMode0(int VTIME_VALUE,
+ int VMIN_VALUE)
+
Adjusts the read mode for this terminal device, the read mode is defined by the read timeout value and the minimum
+ number of bytes to read at that time.
+
+ Default value = BLOCKING_READ_ONE_CHAR {0, 1}; defined by initTermios0().
+
+
Parameters:
+
VTIME_VALUE - the value of the read timeout, applied only when the first index of [mode] is 1 (aka read timeout is activated).
+
VMIN_VALUE - the value of the minimum byte to read in this time.
+
mode - the read mode in a 2 lengthed array format, where first index refers to the timeout config and second index
+ refers to the bytes config.
+
Returns:
+
errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
Gets the read configuration for this terminal device defining the timeout value as the first index and
+ the minimum number of read byte in this timeout as the second index.
+
+ Default value = BLOCKING_READ_ONE_CHAR {0, 1}; defined by initTermios0().
+
+
Returns:
+
an array refering to the read mode, where index [0] represents the read timeout, index [1] represents
+ the minimum bytes to read.
+
+
+
+
+
+
getErrno0
+
protectedintgetErrno0()
+
Retrieves the last error encountered by the native code,
+
+
Returns:
+
the last error code from the native invalid input: '<'errno.h>.
+
+
+
+
+
+
fetchSerialPorts0
+
protectedintfetchSerialPorts0()
+
Fetches the available system teletype terminal devices (tty) located within "/dev" directory
+ and insert the result into serialPorts.
+
+
Returns:
+
errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+
+
+
+
+
+
getBaudRate0
+
protectedintgetBaudRate0()
+
Retrieves the baud rate POSIX code for this terminal process, find more at invalid input: '<'./usr/include/x86_64-linux-gnu/bits/termios.h>.
+
+
Returns:
+
the baud rate code in integers.
+
+
+
+
+
+
writeData0
+
protectedlongwriteData0(int data)
+
Writes an integer buffer to this terminal device.
+
+
Parameters:
+
data - an integer data buffer to write up-to 32-bit.
+
Returns:
+
the number of written bytes in long format.
+
+
+
+
+
+
readData0
+
protectedlongreadData0()
+
Reads the data from the terminal device and inserts the result into an integer buffer
+ readData.
+
+
Returns:
+
the number of read bytes.
+
+
+
+
+
+
writeBuffer0
+
protectedlongwriteBuffer0(String buffer,
+ int length)
+
Writes a string buffer (const char*) with a length to this terminal device.
+
+
Parameters:
+
buffer - a string buffer to write to this terminal device.
+
length - the string buffer length in integers, this minimizes the jni native calls.
+
Returns:
+
the number of written bytes to this terminal device.
+
+
+
+
+
+
readBuffer0
+
protectedlongreadBuffer0()
+
Reads the data from this terminal device and insert the result into the readBuffer
+ string buffer.
+
+
Returns:
+
the number of read bytes from this terminal device.
Returns the enum constant of this class with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this class. (Extraneous whitespace characters are
+not permitted.)
+
+
Parameters:
+
name - the name of the enum constant to be returned.
Instantiates a new serial port for a terminal device with a port path.
+ The rest of the port data is assigned from the jni side after opening the device.
+
+
Parameters:
+
path - the port path on the file system.
+
+
+
+
+
+
+
+
+
+
Method Details
+
+
+
+
getIOFlag
+
publicintgetIOFlag()
+
Gets the io flags defined by the Permissions.
+ The io flags setter is assigned from the jni side by
+
+invalid @link
+
Dispatched whenever a data frame is completely received at the
+
+invalid @link
+
serial.entity.impl.SerialReadEntity
+
+ end
+ when [Return-Carriage/Newline] check is enabled as it specifies a particular data frame.
+
+ This method is dispatched on the
+
+invalid @link
+
Represents codes for the POSIX Systems baud rates and their real values
+ defined from invalid input: '<'./usr/include/x86_64-linux-gnu/bits/termios.h>.
public final class OperationFailedException
+extends SerialThrowable
+
Implements an operation failed exception with error code [EOPERATION_FAILED] or [-1].
+ Possibly thrown from a failed operation, for example trying to open a read-only device.
public class PermissionDeniedException
+extends SerialThrowable
+
Implements a permission exception for error code [EACCESS] or [13] as defined by invalid input: '<'errno.h>.
+ Possibly thrown from non-authorized permissions from a non-root user during an attempt to open
+ a system resource.
Returns the enum constant of this class with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this class. (Extraneous whitespace characters are
+not permitted.)
+
+
Parameters:
+
name - the name of the enum constant to be returned.
Returns the enum constant of this class with the specified name.
+The string must match exactly an identifier used to declare an
+enum constant in this class. (Extraneous whitespace characters are
+not permitted.)
+
+
Parameters:
+
name - the name of the enum constant to be returned.
Dispatched whenever a data frame is completely received at the
+
+invalid @link
+
serial.entity.impl.SerialReadEntity
+
+ end
+ when [Return-Carriage/Newline] check is enabled as it specifies a particular data frame.
+
+ This method is dispatched on the
+
+invalid @link
+
public final class HelloNativeSerial4J
+extends Object
+implements Runnable
+
An example for Serial4j showing Native terminal control and
+ native file io on a serial port using a java binding to invalid input: '<'fcntl.h> and invalid input: '<'unistd.h> read (...) and write (...).
An example for Serial4j showing Native terminal control and
+ native file io on a serial port using a java binding to invalid input: '<'fcntl.h> and invalid input: '<'unistd.h> read (...) and write (...).
+Starting from the Overview page, you can browse the documentation using the links in each page, and in the navigation bar at the top of each page. The Index and Search box allow you to navigate to specific declarations and summary pages, including: All Packages, All Classes and Interfaces
+
+
Search
+
You can search for definitions of modules, packages, types, fields, methods, system properties and other terms defined in the API. These items can be searched using part or all of the name, optionally using "camelCase" abbreviations, or multiple search terms separated by whitespace. Some examples:
+The following sections describe the different kinds of pages in this collection.
+
+
Overview
+
The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
+
+
+
Package
+
Each package has a page that contains a list of its classes and interfaces, with a summary for each. These pages may contain the following categories:
+
+
Interfaces
+
Classes
+
Enum Classes
+
Exception Classes
+
Annotation Interfaces
+
+
+
+
Class or Interface
+
Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a declaration and description, member summary tables, and detailed member descriptions. Entries in each of these sections are omitted if they are empty or not applicable.
+
+
Class Inheritance Diagram
+
Direct Subclasses
+
All Known Subinterfaces
+
All Known Implementing Classes
+
Class or Interface Declaration
+
Class or Interface Description
+
+
+
+
Nested Class Summary
+
Enum Constant Summary
+
Field Summary
+
Property Summary
+
Constructor Summary
+
Method Summary
+
Required Element Summary
+
Optional Element Summary
+
+
+
+
Enum Constant Details
+
Field Details
+
Property Details
+
Constructor Details
+
Method Details
+
Element Details
+
+
Note: Annotation interfaces have required and optional elements, but not methods. Only enum classes have enum constants. The components of a record class are displayed as part of the declaration of the record class. Properties are a feature of JavaFX.
+
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.
+
+
+
Other Files
+
Packages and modules may contain pages with additional information related to the declarations nearby.
+
+
+
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. Classes are organized by inheritance structure starting with java.lang.Object. 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 on TREE displays the hierarchy for only that package.
Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to those who implement rather than use 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.
+
+
+
All Packages
+
The All Packages page contains an alphabetic index of all packages contained in the documentation.
+
+
+
All Classes and Interfaces
+
The All Classes and Interfaces page contains an alphabetic index of all classes and interfaces contained in the documentation, including annotation interfaces, enum classes, and record classes.
+
+
+
Index
+
The Index contains an alphabetic index of all classes, interfaces, constructors, methods, and fields in the documentation, as well as summary pages such as All Packages, All Classes and Interfaces.
+
+
+
+This help file applies to API documentation generated by the standard doclet.
+
Represents codes for the POSIX Systems baud rates and their real values
+ defined from invalid input: '<'./usr/include/x86_64-linux-gnu/bits/termios.h>.
Fetches the available system teletype terminal devices (tty) located within "/dev" directory
+ and insert the result into NativeTerminalDevice.serialPorts.
Gets the read configuration for this terminal device defining the timeout value as the first index and
+ the minimum number of read byte in this timeout as the second index.
An example for Serial4j showing Native terminal control and
+ native file io on a serial port using a java binding to invalid input: '<'fcntl.h> and invalid input: '<'unistd.h> read (...) and write (...).
Adjusts the read mode for this terminal device, the read mode is defined by the read timeout value and the minimum
+ number of bytes to read at that time.
The help page provides an introduction to the scope and syntax of JavaDoc search.
+
You can use the <ctrl> or <cmd> keys in combination with the left and right arrow keys to switch between result tabs in this page.
+
The URL template below may be used to configure this page as a search engine in browsers that support this feature. It has been tested to work in Google Chrome and Mozilla Firefox. Note that other browsers may not support this feature or require a different URL format.
+link
+
+
+
+
+
Loading search index...
+
+
+
+
+
+
+
+
+
diff --git a/HelloSerial4j/serial4j-0.3A-javadoc/search.js b/HelloSerial4j/serial4j-0.3A-javadoc/search.js
new file mode 100644
index 00000000..985016db
--- /dev/null
+++ b/HelloSerial4j/serial4j-0.3A-javadoc/search.js
@@ -0,0 +1,465 @@
+/*
+ * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
+ * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+"use strict";
+const messages = {
+ enterTerm: "Enter a search term",
+ noResult: "No results found",
+ oneResult: "Found one result",
+ manyResults: "Found {0} results",
+ loading: "Loading search index...",
+ searching: "Searching...",
+ redirecting: "Redirecting to first result...",
+ copyUrl: "Copy URL",
+ urlCopied: "Copied!"
+}
+const categories = {
+ modules: "Modules",
+ packages: "Packages",
+ types: "Classes and Interfaces",
+ members: "Members",
+ searchTags: "Search Tags"
+};
+const highlight = "$&";
+const NO_MATCH = {};
+const MAX_RESULTS = 500;
+function checkUnnamed(name, separator) {
+ return name === "" || !name ? "" : name + separator;
+}
+function escapeHtml(str) {
+ return str.replace(//g, ">");
+}
+function getHighlightedText(str, boundaries, from, to) {
+ var start = from;
+ var text = "";
+ for (var i = 0; i < boundaries.length; i += 2) {
+ var b0 = boundaries[i];
+ var b1 = boundaries[i + 1];
+ if (b0 >= to || b1 <= from) {
+ continue;
+ }
+ text += escapeHtml(str.slice(start, Math.max(start, b0)));
+ text += "";
+ text += escapeHtml(str.slice(Math.max(start, b0), Math.min(to, b1)));
+ text += "";
+ start = Math.min(to, b1);
+ }
+ text += escapeHtml(str.slice(start, to));
+ return text;
+}
+function getURLPrefix(item, category) {
+ var urlPrefix = "";
+ var slash = "/";
+ if (category === "modules") {
+ return item.l + slash;
+ } else if (category === "packages" && item.m) {
+ return item.m + slash;
+ } else if (category === "types" || category === "members") {
+ if (item.m) {
+ urlPrefix = item.m + slash;
+ } else {
+ $.each(packageSearchIndex, function(index, it) {
+ if (it.m && item.p === it.l) {
+ urlPrefix = it.m + slash;
+ }
+ });
+ }
+ }
+ return urlPrefix;
+}
+function getURL(item, category) {
+ if (item.url) {
+ return item.url;
+ }
+ var url = getURLPrefix(item, category);
+ if (category === "modules") {
+ url += "module-summary.html";
+ } else if (category === "packages") {
+ if (item.u) {
+ url = item.u;
+ } else {
+ url += item.l.replace(/\./g, '/') + "/package-summary.html";
+ }
+ } else if (category === "types") {
+ if (item.u) {
+ url = item.u;
+ } else {
+ url += checkUnnamed(item.p, "/").replace(/\./g, '/') + item.l + ".html";
+ }
+ } else if (category === "members") {
+ url += checkUnnamed(item.p, "/").replace(/\./g, '/') + item.c + ".html" + "#";
+ if (item.u) {
+ url += item.u;
+ } else {
+ url += item.l;
+ }
+ } else if (category === "searchTags") {
+ url += item.u;
+ }
+ item.url = url;
+ return url;
+}
+function createMatcher(term, camelCase) {
+ if (camelCase && !isUpperCase(term)) {
+ return null; // no need for camel-case matcher for lower case query
+ }
+ var pattern = "";
+ var upperCase = [];
+ term.trim().split(/\s+/).forEach(function(w, index, array) {
+ var tokens = w.split(/(?=[A-Z,.()<>?[\/])/);
+ for (var i = 0; i < tokens.length; i++) {
+ var s = tokens[i];
+ // ',' and '?' are the only delimiters commonly followed by space in java signatures
+ pattern += "(" + $.ui.autocomplete.escapeRegex(s).replace(/[,?]/g, "$&\\s*?") + ")";
+ upperCase.push(false);
+ var isWordToken = /\w$/.test(s);
+ if (isWordToken) {
+ if (i === tokens.length - 1 && index < array.length - 1) {
+ // space in query string matches all delimiters
+ pattern += "(.*?)";
+ upperCase.push(isUpperCase(s[0]));
+ } else {
+ if (!camelCase && isUpperCase(s) && s.length === 1) {
+ pattern += "()";
+ } else {
+ pattern += "([a-z0-9$<>?[\\]]*?)";
+ }
+ upperCase.push(isUpperCase(s[0]));
+ }
+ } else {
+ pattern += "()";
+ upperCase.push(false);
+ }
+ }
+ });
+ var re = new RegExp(pattern, "gi");
+ re.upperCase = upperCase;
+ return re;
+}
+function analyzeMatch(matcher, input, startOfName, category) {
+ var from = startOfName;
+ matcher.lastIndex = from;
+ var match = matcher.exec(input);
+ while (!match && from > 1) {
+ from = input.lastIndexOf(".", from - 2) + 1;
+ matcher.lastIndex = from;
+ match = matcher.exec(input);
+ }
+ if (!match) {
+ return NO_MATCH;
+ }
+ var boundaries = [];
+ var matchEnd = match.index + match[0].length;
+ var leftParen = input.indexOf("(");
+ // exclude peripheral matches
+ if (category !== "modules" && category !== "searchTags") {
+ if (leftParen > -1 && leftParen < match.index) {
+ return NO_MATCH;
+ } else if (startOfName - 1 >= matchEnd) {
+ return NO_MATCH;
+ }
+ }
+ var endOfName = leftParen > -1 ? leftParen : input.length;
+ var score = 5;
+ var start = match.index;
+ var prevEnd = -1;
+ for (var i = 1; i < match.length; i += 2) {
+ var isUpper = isUpperCase(input[start]);
+ var isMatcherUpper = matcher.upperCase[i];
+ // capturing groups come in pairs, match and non-match
+ boundaries.push(start, start + match[i].length);
+ // make sure groups are anchored on a left word boundary
+ var prevChar = input[start - 1] || "";
+ var nextChar = input[start + 1] || "";
+ if (start !== 0 && !/[\W_]/.test(prevChar) && !/[\W_]/.test(input[start])) {
+ if (isUpper && (isLowerCase(prevChar) || isLowerCase(nextChar))) {
+ score -= 0.1;
+ } else if (isMatcherUpper && start === prevEnd) {
+ score -= isUpper ? 0.1 : 1.0;
+ } else {
+ return NO_MATCH;
+ }
+ }
+ prevEnd = start + match[i].length;
+ start += match[i].length + match[i + 1].length;
+
+ // lower score for parts of the name that are missing
+ if (match[i + 1] && prevEnd < endOfName) {
+ score -= rateNoise(match[i + 1]);
+ }
+ }
+ // lower score if a type name contains unmatched camel-case parts
+ if (input[matchEnd - 1] !== "." && endOfName > matchEnd)
+ score -= rateNoise(input.slice(matchEnd, endOfName));
+ score -= rateNoise(input.slice(0, Math.max(startOfName, match.index)));
+
+ if (score <= 0) {
+ return NO_MATCH;
+ }
+ return {
+ input: input,
+ score: score,
+ category: category,
+ boundaries: boundaries
+ };
+}
+function isUpperCase(s) {
+ return s !== s.toLowerCase();
+}
+function isLowerCase(s) {
+ return s !== s.toUpperCase();
+}
+function rateNoise(str) {
+ return (str.match(/([.(])/g) || []).length / 5
+ + (str.match(/([A-Z]+)/g) || []).length / 10
+ + str.length / 20;
+}
+function doSearch(request, response) {
+ var term = request.term.trim();
+ var maxResults = request.maxResults || MAX_RESULTS;
+ if (term.length === 0) {
+ return this.close();
+ }
+ var matcher = {
+ plainMatcher: createMatcher(term, false),
+ camelCaseMatcher: createMatcher(term, true)
+ }
+ var indexLoaded = indexFilesLoaded();
+
+ function getPrefix(item, category) {
+ switch (category) {
+ case "packages":
+ return checkUnnamed(item.m, "/");
+ case "types":
+ return checkUnnamed(item.p, ".");
+ case "members":
+ return checkUnnamed(item.p, ".") + item.c + ".";
+ default:
+ return "";
+ }
+ }
+ function useQualifiedName(category) {
+ switch (category) {
+ case "packages":
+ return /[\s/]/.test(term);
+ case "types":
+ case "members":
+ return /[\s.]/.test(term);
+ default:
+ return false;
+ }
+ }
+ function searchIndex(indexArray, category) {
+ var matches = [];
+ if (!indexArray) {
+ if (!indexLoaded) {
+ matches.push({ l: messages.loading, category: category });
+ }
+ return matches;
+ }
+ $.each(indexArray, function (i, item) {
+ var prefix = getPrefix(item, category);
+ var simpleName = item.l;
+ var qualifiedName = prefix + simpleName;
+ var useQualified = useQualifiedName(category);
+ var input = useQualified ? qualifiedName : simpleName;
+ var startOfName = useQualified ? prefix.length : 0;
+ var m = analyzeMatch(matcher.plainMatcher, input, startOfName, category);
+ if (m === NO_MATCH && matcher.camelCaseMatcher) {
+ m = analyzeMatch(matcher.camelCaseMatcher, input, startOfName, category);
+ }
+ if (m !== NO_MATCH) {
+ m.indexItem = item;
+ m.prefix = prefix;
+ if (!useQualified) {
+ m.input = qualifiedName;
+ m.boundaries = m.boundaries.map(function(b) {
+ return b + prefix.length;
+ });
+ }
+ matches.push(m);
+ }
+ return matches.length < maxResults;
+ });
+ return matches.sort(function(e1, e2) {
+ return e2.score - e1.score;
+ });
+ }
+
+ var result = searchIndex(moduleSearchIndex, "modules")
+ .concat(searchIndex(packageSearchIndex, "packages"))
+ .concat(searchIndex(typeSearchIndex, "types"))
+ .concat(searchIndex(memberSearchIndex, "members"))
+ .concat(searchIndex(tagSearchIndex, "searchTags"));
+
+ if (!indexLoaded) {
+ updateSearchResults = function() {
+ doSearch(request, response);
+ }
+ } else {
+ updateSearchResults = function() {};
+ }
+ response(result);
+}
+// JQuery search menu implementation
+$.widget("custom.catcomplete", $.ui.autocomplete, {
+ _create: function() {
+ this._super();
+ this.widget().menu("option", "items", "> .result-item");
+ // workaround for search result scrolling
+ this.menu._scrollIntoView = function _scrollIntoView( item ) {
+ var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
+ if ( this._hasScroll() ) {
+ borderTop = parseFloat( $.css( this.activeMenu[ 0 ], "borderTopWidth" ) ) || 0;
+ paddingTop = parseFloat( $.css( this.activeMenu[ 0 ], "paddingTop" ) ) || 0;
+ offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
+ scroll = this.activeMenu.scrollTop();
+ elementHeight = this.activeMenu.height() - 26;
+ itemHeight = item.outerHeight();
+
+ if ( offset < 0 ) {
+ this.activeMenu.scrollTop( scroll + offset );
+ } else if ( offset + itemHeight > elementHeight ) {
+ this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
+ }
+ }
+ };
+ },
+ _renderMenu: function(ul, items) {
+ var currentCategory = "";
+ var widget = this;
+ widget.menu.bindings = $();
+ $.each(items, function(index, item) {
+ if (item.category && item.category !== currentCategory) {
+ ul.append("
+
+
diff --git a/HelloSerial4j/serial4j-0.3A-javadoc/stylesheet.css b/HelloSerial4j/serial4j-0.3A-javadoc/stylesheet.css
new file mode 100644
index 00000000..d3309916
--- /dev/null
+++ b/HelloSerial4j/serial4j-0.3A-javadoc/stylesheet.css
@@ -0,0 +1,1204 @@
+/*
+ * Javadoc style sheet
+ */
+
+@import url('resources/fonts/dejavu.css');
+
+/*
+ * Styles for individual HTML elements.
+ *
+ * These are styles that are specific to individual HTML elements. Changing them affects the style of a particular
+ * HTML element throughout the page.
+ */
+
+body {
+ background-color:#ffffff;
+ color:#353833;
+ font-family:'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size:14px;
+ margin:0;
+ padding:0;
+ height:100%;
+ width:100%;
+}
+iframe {
+ margin:0;
+ padding:0;
+ height:100%;
+ width:100%;
+ overflow-y:scroll;
+ border:none;
+}
+a:link, a:visited {
+ text-decoration:none;
+ color:#4A6782;
+}
+a[href]:hover, a[href]:focus {
+ text-decoration:none;
+ color:#bb7a2a;
+}
+a[name] {
+ color:#353833;
+}
+pre {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+}
+h1 {
+ font-size:20px;
+}
+h2 {
+ font-size:18px;
+}
+h3 {
+ font-size:16px;
+}
+h4 {
+ font-size:15px;
+}
+h5 {
+ font-size:14px;
+}
+h6 {
+ font-size:13px;
+}
+/* Disable font boosting for selected elements */
+h1, h2, h3, h4, h5, h6, div.member-signature {
+ max-height: 1000em;
+}
+ul {
+ list-style-type:disc;
+}
+code, tt {
+ font-family:'DejaVu Sans Mono', monospace;
+}
+:not(h1, h2, h3, h4, h5, h6) > code,
+:not(h1, h2, h3, h4, h5, h6) > tt {
+ 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;
+}
+.summary-table dt code {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ vertical-align:top;
+ padding-top:4px;
+}
+sup {
+ font-size:8px;
+}
+button {
+ font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size: 14px;
+}
+/*
+ * Styles for HTML generated by javadoc.
+ *
+ * These are style classes that are used by the standard doclet to generate HTML documentation.
+ */
+
+/*
+ * Styles for document title and copyright.
+ */
+.about-language {
+ float:right;
+ padding:0 21px 8px 8px;
+ font-size:11px;
+ margin-top:-9px;
+ height:2.9em;
+}
+.legal-copy {
+ margin-left:.5em;
+}
+/*
+ * Styles for navigation bar.
+ */
+@media screen {
+ div.flex-box {
+ position:fixed;
+ display:flex;
+ flex-direction:column;
+ height: 100%;
+ width: 100%;
+ }
+ header.flex-header {
+ flex: 0 0 auto;
+ }
+ div.flex-content {
+ flex: 1 1 auto;
+ overflow-y: auto;
+ }
+}
+.top-nav {
+ background-color:#4D7A97;
+ color:#FFFFFF;
+ float:left;
+ padding:0;
+ width:100%;
+ clear:right;
+ min-height:2.8em;
+ padding-top:10px;
+ overflow:hidden;
+ font-size:12px;
+}
+button#navbar-toggle-button {
+ display:none;
+}
+ul.sub-nav-list-small {
+ display: none;
+}
+.sub-nav {
+ background-color:#dee3e9;
+ float:left;
+ width:100%;
+ overflow:hidden;
+ font-size:12px;
+}
+.sub-nav div {
+ clear:left;
+ float:left;
+ padding:6px;
+ text-transform:uppercase;
+}
+.sub-nav .sub-nav-list {
+ padding-top:4px;
+}
+ul.nav-list {
+ display:block;
+ margin:0 25px 0 0;
+ padding:0;
+}
+ul.sub-nav-list {
+ float:left;
+ margin:0 25px 0 0;
+ padding:0;
+}
+ul.nav-list li {
+ list-style:none;
+ float:left;
+ padding: 5px 6px;
+ text-transform:uppercase;
+}
+.sub-nav .nav-list-search {
+ float:right;
+ margin:0;
+ padding:6px;
+ clear:none;
+ text-align:right;
+ position:relative;
+}
+ul.sub-nav-list li {
+ list-style:none;
+ float:left;
+}
+.top-nav a:link, .top-nav a:active, .top-nav a:visited {
+ color:#ffffff;
+ text-decoration:none;
+ text-transform:uppercase;
+}
+.top-nav a:hover {
+ color:#bb7a2a;
+}
+.nav-bar-cell1-rev {
+ background-color:#F8981D;
+ color:#253441;
+ margin: auto 5px;
+}
+.skip-nav {
+ position:absolute;
+ top:auto;
+ left:-9999px;
+ overflow:hidden;
+}
+/*
+ * Hide navigation links and search box in print layout
+ */
+@media print {
+ ul.nav-list, div.sub-nav {
+ display:none;
+ }
+}
+/*
+ * Styles for page header.
+ */
+.title {
+ color:#2c4557;
+ margin:10px 0;
+}
+.sub-title {
+ margin:5px 0 0 0;
+}
+.header ul {
+ margin:0 0 15px 0;
+ padding:0;
+}
+.header ul li {
+ list-style:none;
+ font-size:13px;
+}
+/*
+ * Styles for headings.
+ */
+body.class-declaration-page .summary h2,
+body.class-declaration-page .details h2,
+body.class-use-page h2,
+body.module-declaration-page .block-list h2 {
+ font-style: italic;
+ padding:0;
+ margin:15px 0;
+}
+body.class-declaration-page .summary h3,
+body.class-declaration-page .details h3,
+body.class-declaration-page .summary .inherited-list h2 {
+ background-color:#dee3e9;
+ border:1px solid #d0d9e0;
+ margin:0 0 6px -8px;
+ padding:7px 5px;
+}
+/*
+ * Styles for page layout containers.
+ */
+main {
+ clear:both;
+ padding:10px 20px;
+ position:relative;
+}
+dl.notes > dt {
+ font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size:12px;
+ font-weight:bold;
+ margin:10px 0 0 0;
+ color:#4E4E4E;
+}
+dl.notes > dd {
+ margin:5px 10px 10px 0;
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+}
+dl.name-value > dt {
+ margin-left:1px;
+ font-size:1.1em;
+ display:inline;
+ font-weight:bold;
+}
+dl.name-value > dd {
+ margin:0 0 0 1px;
+ font-size:1.1em;
+ display:inline;
+}
+/*
+ * Styles for lists.
+ */
+li.circle {
+ list-style:circle;
+}
+ul.horizontal li {
+ display:inline;
+ font-size:0.9em;
+}
+div.inheritance {
+ margin:0;
+ padding:0;
+}
+div.inheritance div.inheritance {
+ margin-left:2em;
+}
+ul.block-list,
+ul.details-list,
+ul.member-list,
+ul.summary-list {
+ margin:10px 0 10px 0;
+ padding:0;
+}
+ul.block-list > li,
+ul.details-list > li,
+ul.member-list > li,
+ul.summary-list > li {
+ list-style:none;
+ margin-bottom:15px;
+ line-height:1.4;
+}
+.summary-table dl, .summary-table dl dt, .summary-table dl dd {
+ margin-top:0;
+ margin-bottom:1px;
+}
+ul.see-list, ul.see-list-long {
+ padding-left: 0;
+ list-style: none;
+}
+ul.see-list li {
+ display: inline;
+}
+ul.see-list li:not(:last-child):after,
+ul.see-list-long li:not(:last-child):after {
+ content: ", ";
+ white-space: pre-wrap;
+}
+/*
+ * Styles for tables.
+ */
+.summary-table, .details-table {
+ width:100%;
+ border-spacing:0;
+ border-left:1px solid #EEE;
+ border-right:1px solid #EEE;
+ border-bottom:1px solid #EEE;
+ padding:0;
+}
+.caption {
+ position:relative;
+ text-align:left;
+ background-repeat:no-repeat;
+ color:#253441;
+ clear:none;
+ overflow:hidden;
+ padding:0;
+ padding-top:10px;
+ padding-left:1px;
+ margin:0;
+}
+.caption a:link, .caption a:visited {
+ color:#1f389c;
+}
+.caption a:hover,
+.caption a:active {
+ color:#FFFFFF;
+}
+.caption span {
+ font-weight:bold;
+ white-space:nowrap;
+ padding:5px 12px 7px 12px;
+ display:inline-block;
+ float:left;
+ background-color:#F8981D;
+ border: none;
+ height:16px;
+}
+div.table-tabs {
+ padding:10px 0 0 1px;
+ margin:10px 0 0 0;
+}
+div.table-tabs > span {
+ background-color: #EEE;
+ color: #000;
+ border: none;
+ padding: 5px 12px 8px 12px;
+}
+div.table-tabs > button {
+ border: none;
+ cursor: pointer;
+ padding: 5px 12px 7px 12px;
+ font-weight: bold;
+ margin-right: 8px;
+}
+div.table-tabs > .active-table-tab {
+ background: #F8981D;
+ color: #253441;
+}
+div.table-tabs > button.table-tab {
+ background: #4D7A97;
+ color: #FFFFFF;
+}
+.two-column-search-results {
+ display: grid;
+ grid-template-columns: minmax(400px, max-content) minmax(400px, auto);
+}
+div.checkboxes {
+ line-height: 2em;
+}
+div.checkboxes > span {
+ margin-left: 10px;
+}
+div.checkboxes > label {
+ margin-left: 8px;
+ white-space: nowrap;
+}
+div.checkboxes > label > input {
+ margin: 0 2px;
+}
+.two-column-summary {
+ display: grid;
+ grid-template-columns: minmax(25%, max-content) minmax(25%, auto);
+}
+.three-column-summary {
+ display: grid;
+ grid-template-columns: minmax(15%, max-content) minmax(20%, max-content) minmax(20%, auto);
+}
+.three-column-release-summary {
+ display: grid;
+ grid-template-columns: minmax(40%, max-content) minmax(10%, max-content) minmax(40%, auto);
+}
+.four-column-summary {
+ display: grid;
+ grid-template-columns: minmax(10%, max-content) minmax(15%, max-content) minmax(15%, max-content) minmax(15%, auto);
+}
+@media screen and (max-width: 1000px) {
+ .four-column-summary {
+ display: grid;
+ grid-template-columns: minmax(15%, max-content) minmax(15%, auto);
+ }
+}
+@media screen and (max-width: 800px) {
+ .two-column-search-results {
+ display: grid;
+ grid-template-columns: minmax(40%, max-content) minmax(40%, auto);
+ }
+ .three-column-summary {
+ display: grid;
+ grid-template-columns: minmax(10%, max-content) minmax(25%, auto);
+ }
+ .three-column-release-summary {
+ display: grid;
+ grid-template-columns: minmax(70%, max-content) minmax(30%, max-content)
+ }
+ .three-column-summary .col-last,
+ .three-column-release-summary .col-last{
+ grid-column-end: span 2;
+ }
+}
+@media screen and (max-width: 600px) {
+ .two-column-summary {
+ display: grid;
+ grid-template-columns: 1fr;
+ }
+}
+.summary-table > div, .details-table > div {
+ text-align:left;
+ padding: 8px 3px 3px 7px;
+ overflow-x: auto;
+ scrollbar-width: thin;
+}
+.col-first, .col-second, .col-last, .col-constructor-name, .col-summary-item-name {
+ vertical-align:top;
+ padding-right:0;
+ padding-top:8px;
+ padding-bottom:3px;
+}
+.table-header {
+ background:#dee3e9;
+ font-weight: bold;
+}
+/* Sortable table columns */
+.table-header[onclick] {
+ cursor: pointer;
+}
+.table-header[onclick]::after {
+ content:"";
+ display:inline-block;
+ background-image:url('data:image/svg+xml; utf8, \
+ ');
+ background-size:100% 100%;
+ width:9px;
+ height:14px;
+ margin-left:4px;
+ margin-bottom:-3px;
+}
+.table-header[onclick].sort-asc::after {
+ background-image:url('data:image/svg+xml; utf8, \
+ ');
+
+}
+.table-header[onclick].sort-desc::after {
+ background-image:url('data:image/svg+xml; utf8, \
+ ');
+}
+.col-first, .col-first {
+ font-size:13px;
+}
+.col-second, .col-second, .col-last, .col-constructor-name, .col-summary-item-name, .col-last {
+ font-size:13px;
+}
+.col-first, .col-second, .col-constructor-name {
+ vertical-align:top;
+ overflow: auto;
+}
+.col-last {
+ white-space:normal;
+}
+.col-first a:link, .col-first a:visited,
+.col-second a:link, .col-second a:visited,
+.col-first a:link, .col-first a:visited,
+.col-second a:link, .col-second a:visited,
+.col-constructor-name a:link, .col-constructor-name a:visited,
+.col-summary-item-name a:link, .col-summary-item-name a:visited {
+ font-weight:bold;
+}
+.even-row-color, .even-row-color .table-header {
+ background-color:#FFFFFF;
+}
+.odd-row-color, .odd-row-color .table-header {
+ background-color:#EEEEEF;
+}
+/*
+ * Styles for contents.
+ */
+div.block {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+}
+.col-last div {
+ padding-top:0;
+}
+.col-last a {
+ padding-bottom:3px;
+}
+.module-signature,
+.package-signature,
+.type-signature,
+.member-signature {
+ font-family:'DejaVu Sans Mono', monospace;
+ font-size:14px;
+ margin:14px 0;
+ white-space: pre-wrap;
+}
+.module-signature,
+.package-signature,
+.type-signature {
+ margin-top: 0;
+}
+.member-signature .type-parameters-long,
+.member-signature .parameters,
+.member-signature .exceptions {
+ display: inline-block;
+ vertical-align: top;
+ white-space: pre;
+}
+.member-signature .type-parameters {
+ white-space: normal;
+}
+/*
+ * Styles for formatting effect.
+ */
+.source-line-no {
+ color:green;
+ padding:0 30px 0 0;
+}
+.block {
+ display:block;
+ margin:0 10px 5px 0;
+ color:#474747;
+}
+.deprecated-label, .description-from-type-label, .implementation-label, .member-name-link,
+.module-label-in-package, .module-label-in-type, .package-label-in-type,
+.package-hierarchy-label, .type-name-label, .type-name-link, .search-tag-link, .preview-label {
+ font-weight:bold;
+}
+.deprecation-comment, .help-footnote, .preview-comment {
+ font-style:italic;
+}
+.deprecation-block {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+ border-style:solid;
+ border-width:thin;
+ border-radius:10px;
+ padding:10px;
+ margin-bottom:10px;
+ margin-right:10px;
+ display:inline-block;
+}
+.preview-block {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+ border-style:solid;
+ border-width:thin;
+ border-radius:10px;
+ padding:10px;
+ margin-bottom:10px;
+ margin-right:10px;
+ display:inline-block;
+}
+div.block div.deprecation-comment {
+ font-style:normal;
+}
+details.invalid-tag, span.invalid-tag {
+ font-size:14px;
+ font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif;
+ background: #ffe6e6;
+ border: thin solid #000000;
+ border-radius:2px;
+ padding: 2px 4px;
+ display:inline-block;
+}
+details summary {
+ cursor: pointer;
+}
+/*
+ * Styles specific to HTML5 elements.
+ */
+main, nav, header, footer, section {
+ display:block;
+}
+/*
+ * Styles for javadoc search.
+ */
+.ui-autocomplete-category {
+ font-weight:bold;
+ font-size:15px;
+ padding:7px 0 7px 3px;
+ background-color:#4D7A97;
+ color:#FFFFFF;
+}
+.ui-autocomplete {
+ max-height:85%;
+ max-width:65%;
+ overflow-y:auto;
+ overflow-x:auto;
+ scrollbar-width: thin;
+ white-space:nowrap;
+ box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
+}
+ul.ui-autocomplete {
+ position:fixed;
+ z-index:1;
+ background-color: #FFFFFF;
+}
+ul.ui-autocomplete li {
+ float:left;
+ clear:both;
+ min-width:100%;
+}
+ul.ui-autocomplete li.ui-static-link {
+ position:sticky;
+ bottom:0;
+ left:0;
+ background: #dee3e9;
+ padding: 5px 0;
+ font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif;
+ font-size: 13px;
+ font-weight: bolder;
+ z-index: 2;
+}
+li.ui-static-link a, li.ui-static-link a:visited {
+ text-decoration:none;
+ color:#4A6782;
+ float:right;
+ margin-right:20px;
+}
+.ui-autocomplete .result-item {
+ font-size: inherit;
+}
+.ui-autocomplete .result-highlight {
+ font-weight:bold;
+}
+#search-input, #page-search-input {
+ background-image:url('resources/glass.png');
+ background-size:13px;
+ background-repeat:no-repeat;
+ background-position:2px 3px;
+ padding-left:20px;
+ width: 250px;
+ margin: 0;
+}
+#search-input {
+ margin-left: 4px;
+}
+#reset-button {
+ background-color: transparent;
+ background-image:url('resources/x.png');
+ background-repeat:no-repeat;
+ background-size:contain;
+ border:0;
+ border-radius:0;
+ width:12px;
+ height:12px;
+ position:absolute;
+ right:12px;
+ top:10px;
+ font-size:0;
+}
+::placeholder {
+ color:#909090;
+ opacity: 1;
+}
+.search-tag-desc-result {
+ font-style:italic;
+ font-size:11px;
+}
+.search-tag-holder-result {
+ font-style:italic;
+ font-size:12px;
+}
+.search-tag-result:target {
+ background-color:yellow;
+}
+details.page-search-details {
+ display: inline-block;
+}
+div#result-container {
+ font-size: 14px;
+}
+div#result-container a.search-result-link {
+ padding: 0;
+ margin: 4px 0;
+ width: 100%;
+}
+#result-container .result-highlight {
+ font-weight:bolder;
+}
+.page-search-info {
+ background-color: #f5f8ff;
+ border-radius: 3px;
+ border: 0 solid #b9c8d3;
+ padding: 0 8px;
+ overflow: hidden;
+ height: 0;
+ transition: all 0.2s ease;
+}
+div.table-tabs > button.table-tab {
+ background: #4D7A97;
+ color: #FFFFFF;
+}
+.page-search-header {
+ padding: 5px 12px 7px 12px;
+ font-weight: bold;
+ margin-right: 3px;
+ background-color:#4D7A97;
+ color:#ffffff;
+ display: inline-block;
+}
+button.page-search-header {
+ border: none;
+ cursor: pointer;
+}
+span#page-search-link {
+ text-decoration: underline;
+}
+.module-graph span {
+ display:none;
+ position:absolute;
+}
+.module-graph:hover span {
+ display:block;
+ margin: -100px 0 0 100px;
+ z-index: 1;
+}
+.inherited-list {
+ margin: 10px 0 10px 0;
+}
+section.class-description {
+ line-height: 1.4;
+}
+.summary section[class$="-summary"], .details section[class$="-details"],
+.class-uses .detail, .serialized-class-details {
+ padding: 0px 20px 5px 10px;
+ border: 1px solid #ededed;
+ background-color: #f8f8f8;
+}
+.inherited-list, section[class$="-details"] .detail {
+ padding:0 0 5px 8px;
+ background-color:#ffffff;
+ border:none;
+}
+.vertical-separator {
+ padding: 0 5px;
+}
+ul.help-section-list {
+ margin: 0;
+}
+ul.help-subtoc > li {
+ display: inline-block;
+ padding-right: 5px;
+ font-size: smaller;
+}
+ul.help-subtoc > li::before {
+ content: "\2022" ;
+ padding-right:2px;
+}
+.help-note {
+ font-style: italic;
+}
+/*
+ * Indicator icon for external links.
+ */
+main a[href*="://"]::after {
+ content:"";
+ display:inline-block;
+ background-image:url('data:image/svg+xml; utf8, \
+ ');
+ background-size:100% 100%;
+ width:7px;
+ height:7px;
+ margin-left:2px;
+ margin-bottom:4px;
+}
+main a[href*="://"]:hover::after,
+main a[href*="://"]:focus::after {
+ background-image:url('data:image/svg+xml; utf8, \
+ ');
+}
+/*
+ * Styles for copy-to-clipboard buttons
+ */
+button.copy {
+ opacity: 80%;
+ border: none;
+ border-radius: 3px;
+ position: relative;
+ background:none;
+ transition: opacity 0.2s;
+ cursor: pointer;
+}
+button.copy:hover,
+button.copy:active {
+ opacity: 100%;
+}
+button.copy img {
+ position: relative;
+ background: none;
+}
+button.copy span {
+ color: #303030;
+ position: relative;
+ top: -0.1em;
+ transition: all 0.1s;
+ font-size: 85%;
+ line-height: 1.2em;
+}
+/* header/section copy button */
+button.copy-header {
+ margin: 0 0.2em;
+ padding: 0 4px;
+ height: 1.35em;
+}
+button.copy-header img {
+ height: 1em;
+ top: 0.1em;
+}
+button.copy-header:active {
+ background-color: rgba(128, 128, 160, 0.2);
+}
+/* search page copy button */
+button#page-search-copy {
+ margin-left: 0.4em;
+ padding:0.3em;
+ top:0.13em;
+}
+button#page-search-copy img {
+ width: 1.2em;
+ height: 1.2em;
+ padding: 0.01em 0;
+ top: 0.15em;
+}
+button#page-search-copy span {
+ color: #000000;
+ content: attr(aria-label);
+ line-height: 1.2em;
+ padding: 0.2em;
+ top: -0.18em;
+ opacity: 0;
+}
+div.page-search-info:hover button#page-search-copy,
+div.page-search-info:hover button#page-search-copy span {
+ opacity: 90%;
+}
+div.page-search-info button#page-search-copy:hover {
+ background-color: #dfe6f1;
+}
+div.page-search-info button#page-search-copy:active {
+ background-color: #cfdbee;
+}
+/* snippet copy button */
+button.snippet-copy {
+ position: absolute;
+ top: 6px;
+ right: 6px;
+ height: 1.7em;
+ opacity: 50%;
+ padding: 2px;
+}
+button.snippet-copy img {
+ width: 18px;
+ height: 18px;
+ padding: 0.05em 0;
+}
+button.snippet-copy span {
+ content: attr(aria-label);
+ line-height: 1.2em;
+ padding: 0.2em;
+ position: relative;
+ top: -0.5em;
+ display: none;
+}
+div.snippet-container:hover button.snippet-copy span {
+ display: inline;
+}
+div.snippet-container:hover button.snippet-copy {
+ opacity: 80%;
+}
+div.snippet-container button.snippet-copy:hover {
+ opacity: 100%;
+}
+button.snippet-copy:active {
+ background: #d3d3d3;
+}
+/*
+ * Styles for user-provided tables.
+ *
+ * borderless:
+ * No borders, vertical margins, styled caption.
+ * This style is provided for use with existing doc comments.
+ * In general, borderless tables should not be used for layout purposes.
+ *
+ * plain:
+ * Plain borders around table and cells, vertical margins, styled caption.
+ * Best for small tables or for complex tables for tables with cells that span
+ * rows and columns, when the "striped" style does not work well.
+ *
+ * striped:
+ * Borders around the table and vertical borders between cells, striped rows,
+ * vertical margins, styled caption.
+ * Best for tables that have a header row, and a body containing a series of simple rows.
+ */
+
+table.borderless,
+table.plain,
+table.striped {
+ margin-top: 10px;
+ margin-bottom: 10px;
+}
+table.borderless > caption,
+table.plain > caption,
+table.striped > caption {
+ font-weight: bold;
+ font-size: smaller;
+}
+table.borderless th, table.borderless td,
+table.plain th, table.plain td,
+table.striped th, table.striped td {
+ padding: 2px 5px;
+}
+table.borderless,
+table.borderless > thead > tr > th, table.borderless > tbody > tr > th, table.borderless > tr > th,
+table.borderless > thead > tr > td, table.borderless > tbody > tr > td, table.borderless > tr > td {
+ border: none;
+}
+table.borderless > thead > tr, table.borderless > tbody > tr, table.borderless > tr {
+ background-color: transparent;
+}
+table.plain {
+ border-collapse: collapse;
+ border: 1px solid black;
+}
+table.plain > thead > tr, table.plain > tbody tr, table.plain > tr {
+ background-color: transparent;
+}
+table.plain > thead > tr > th, table.plain > tbody > tr > th, table.plain > tr > th,
+table.plain > thead > tr > td, table.plain > tbody > tr > td, table.plain > tr > td {
+ border: 1px solid black;
+}
+table.striped {
+ border-collapse: collapse;
+ border: 1px solid black;
+}
+table.striped > thead {
+ background-color: #E3E3E3;
+}
+table.striped > thead > tr > th, table.striped > thead > tr > td {
+ border: 1px solid black;
+}
+table.striped > tbody > tr:nth-child(even) {
+ background-color: #EEE
+}
+table.striped > tbody > tr:nth-child(odd) {
+ background-color: #FFF
+}
+table.striped > tbody > tr > th, table.striped > tbody > tr > td {
+ border-left: 1px solid black;
+ border-right: 1px solid black;
+}
+table.striped > tbody > tr > th {
+ font-weight: normal;
+}
+/**
+ * Tweak style for small screens.
+ */
+@media screen and (max-width: 920px) {
+ header.flex-header {
+ max-height: 100vh;
+ overflow-y: auto;
+ }
+ div#navbar-top {
+ height: 2.8em;
+ transition: height 0.35s ease;
+ }
+ ul.nav-list {
+ display: block;
+ width: 40%;
+ float:left;
+ clear: left;
+ margin: 10px 0 0 0;
+ padding: 0;
+ }
+ ul.nav-list li {
+ float: none;
+ padding: 6px;
+ margin-left: 10px;
+ margin-top: 2px;
+ }
+ ul.sub-nav-list-small {
+ display:block;
+ height: 100%;
+ width: 50%;
+ float: right;
+ clear: right;
+ background-color: #dee3e9;
+ color: #353833;
+ margin: 6px 0 0 0;
+ padding: 0;
+ }
+ ul.sub-nav-list-small ul {
+ padding-left: 20px;
+ }
+ ul.sub-nav-list-small a:link, ul.sub-nav-list-small a:visited {
+ color:#4A6782;
+ }
+ ul.sub-nav-list-small a:hover {
+ color:#bb7a2a;
+ }
+ ul.sub-nav-list-small li {
+ list-style:none;
+ float:none;
+ padding: 6px;
+ margin-top: 1px;
+ text-transform:uppercase;
+ }
+ ul.sub-nav-list-small > li {
+ margin-left: 10px;
+ }
+ ul.sub-nav-list-small li p {
+ margin: 5px 0;
+ }
+ div#navbar-sub-list {
+ display: none;
+ }
+ .top-nav a:link, .top-nav a:active, .top-nav a:visited {
+ display: block;
+ }
+ button#navbar-toggle-button {
+ width: 3.4em;
+ height: 2.8em;
+ background-color: transparent;
+ display: block;
+ float: left;
+ border: 0;
+ margin: 0 10px;
+ cursor: pointer;
+ font-size: 10px;
+ }
+ button#navbar-toggle-button .nav-bar-toggle-icon {
+ display: block;
+ width: 24px;
+ height: 3px;
+ margin: 1px 0 4px 0;
+ border-radius: 2px;
+ transition: all 0.1s;
+ background-color: #ffffff;
+ }
+ button#navbar-toggle-button.expanded span.nav-bar-toggle-icon:nth-child(1) {
+ transform: rotate(45deg);
+ transform-origin: 10% 10%;
+ width: 26px;
+ }
+ button#navbar-toggle-button.expanded span.nav-bar-toggle-icon:nth-child(2) {
+ opacity: 0;
+ }
+ button#navbar-toggle-button.expanded span.nav-bar-toggle-icon:nth-child(3) {
+ transform: rotate(-45deg);
+ transform-origin: 10% 90%;
+ width: 26px;
+ }
+}
+@media screen and (max-width: 800px) {
+ .about-language {
+ padding-right: 16px;
+ }
+ ul.nav-list li {
+ margin-left: 5px;
+ }
+ ul.sub-nav-list-small > li {
+ margin-left: 5px;
+ }
+ main {
+ padding: 10px;
+ }
+ .summary section[class$="-summary"], .details section[class$="-details"],
+ .class-uses .detail, .serialized-class-details {
+ padding: 0 8px 5px 8px;
+ }
+ body {
+ -webkit-text-size-adjust: none;
+ }
+}
+@media screen and (max-width: 400px) {
+ .about-language {
+ font-size: 10px;
+ padding-right: 12px;
+ }
+}
+@media screen and (max-width: 400px) {
+ .nav-list-search {
+ width: 94%;
+ }
+ #search-input, #page-search-input {
+ width: 70%;
+ }
+}
+@media screen and (max-width: 320px) {
+ .nav-list-search > label {
+ display: none;
+ }
+ .nav-list-search {
+ width: 90%;
+ }
+ #search-input, #page-search-input {
+ width: 80%;
+ }
+}
+
+pre.snippet {
+ background-color: #ebecee;
+ padding: 10px;
+ margin: 12px 0;
+ overflow: auto;
+ white-space: pre;
+}
+div.snippet-container {
+ position: relative;
+}
+@media screen and (max-width: 800px) {
+ pre.snippet {
+ padding-top: 26px;
+ }
+ button.snippet-copy {
+ top: 4px;
+ right: 4px;
+ }
+}
+pre.snippet .italic {
+ font-style: italic;
+}
+pre.snippet .bold {
+ font-weight: bold;
+}
+pre.snippet .highlighted {
+ background-color: #f7c590;
+ border-radius: 10%;
+}
diff --git a/HelloSerial4j/serial4j-0.3A-javadoc/tag-search-index.js b/HelloSerial4j/serial4j-0.3A-javadoc/tag-search-index.js
new file mode 100644
index 00000000..bf10aaf6
--- /dev/null
+++ b/HelloSerial4j/serial4j-0.3A-javadoc/tag-search-index.js
@@ -0,0 +1 @@
+tagSearchIndex = [{"l":"Constant Field Values","h":"","u":"constant-values.html"},{"l":"Serialized Form","h":"","u":"serialized-form.html"}];updateSearchResults();
\ No newline at end of file
diff --git a/HelloSerial4j/serial4j-0.3A-javadoc/type-search-index.js b/HelloSerial4j/serial4j-0.3A-javadoc/type-search-index.js
new file mode 100644
index 00000000..59e931a6
--- /dev/null
+++ b/HelloSerial4j/serial4j-0.3A-javadoc/type-search-index.js
@@ -0,0 +1 @@
+typeSearchIndex = [{"l":"All Classes and Interfaces","u":"allclasses-index.html"},{"p":"com.serial4j.core.serial.throwable","l":"BadFileDescriptorException"},{"p":"com.serial4j.core.serial","l":"BaudRate"},{"p":"com.serial4j.core.serial.throwable","l":"BrokenPipeException"},{"p":"com.serial4j.core.serial.entity","l":"EntityStatus"},{"p":"com.serial4j.core.errno","l":"Errno"},{"p":"com.serial4j.core.errno","l":"ErrnoToException"},{"p":"com.serial4j.core.serial.throwable","l":"FileAlreadyOpenedException"},{"p":"com.serial4j.core.serial.throwable","l":"FileIsDirectoryException"},{"p":"com.serial4j.core.serial.throwable","l":"FileTableOverflowException"},{"p":"com.serial4j.core.serial.throwable","l":"FileTooLargeException"},{"p":"com.serial4j.example.serial4j","l":"HelloNativeSerial4J"},{"p":"com.serial4j.example.serial4j","l":"HelloSerial4jIO"},{"p":"com.serial4j.example.monitor","l":"HelloSerialMonitor"},{"p":"com.serial4j.core.serial.throwable","l":"InputOutputException"},{"p":"com.serial4j.core.serial.throwable","l":"InterruptedSystemCallException"},{"p":"com.serial4j.core.serial.throwable","l":"InvalidArgumentException"},{"p":"com.serial4j.core.serial.throwable","l":"InvalidPortException"},{"p":"com.serial4j.example","l":"Launcher"},{"p":"com.serial4j.core.util.process","l":"Semaphore.Mutex"},{"p":"com.serial4j.core.errno","l":"NativeErrno"},{"p":"com.serial4j.core.util.natives","l":"NativeImageLoader.NativeImage"},{"p":"com.serial4j.core.util.natives","l":"NativeImageLoader"},{"p":"com.serial4j.core.serial","l":"NativeTerminalDevice"},{"p":"com.serial4j.core.serial.throwable","l":"NoAvailableTtyDevicesException"},{"p":"com.serial4j.core.serial.throwable","l":"NoSpaceLeftException"},{"p":"com.serial4j.core.serial.throwable","l":"NoSuchDeviceException"},{"p":"com.serial4j.core.serial.throwable","l":"NoSuchFileException"},{"p":"com.serial4j.core.serial.throwable","l":"NotTtyDeviceException"},{"p":"com.serial4j.core.serial.throwable","l":"OperationFailedException"},{"p":"com.serial4j.core.serial.throwable","l":"PermissionDeniedException"},{"p":"com.serial4j.core.serial","l":"Permissions"},{"p":"com.serial4j.core.serial","l":"ReadConfiguration"},{"p":"com.serial4j.core.serial.throwable","l":"ReadOnlyFileSystemException"},{"p":"com.serial4j.core.util.process","l":"Semaphore"},{"p":"com.serial4j.core.serial.monitor","l":"SerialDataListener"},{"p":"com.serial4j.core.serial.monitor","l":"SerialMonitor"},{"p":"com.serial4j.core.serial.entity","l":"SerialMonitorEntity"},{"p":"com.serial4j.core.serial.monitor","l":"SerialMonitorException"},{"p":"com.serial4j.core.serial","l":"SerialPort"},{"p":"com.serial4j.core.serial.entity.impl","l":"SerialReadEntity"},{"p":"com.serial4j.core.serial.throwable","l":"SerialThrowable"},{"p":"com.serial4j.core.serial.entity.impl","l":"SerialWriteEntity"},{"p":"com.serial4j.core.util.natives","l":"NativeImageLoader.State"},{"p":"com.serial4j.core.serial.control","l":"TerminalControlFlag"},{"p":"com.serial4j.core.serial","l":"TerminalDevice"},{"p":"com.serial4j.core.serial.control","l":"TerminalFlag"},{"p":"com.serial4j.core.serial.control","l":"TerminalInputFlag"},{"p":"com.serial4j.core.serial.control","l":"TerminalLocalFlag"},{"p":"com.serial4j.core.serial.control","l":"TerminalOutputFlag"},{"p":"com.serial4j.core.serial.throwable","l":"TooManyOpenedFilesException"},{"p":"com.serial4j.core.serial.throwable","l":"TryAgainException"},{"p":"com.serial4j.core.serial.entity.impl","l":"WritableCapsule"}];updateSearchResults();
\ No newline at end of file
diff --git a/HelloSerial4j/shared/native/Linux/linux-x86-x64/libserial4j.so b/HelloSerial4j/shared/native/Linux/linux-x86-x64/libserial4j.so
new file mode 100755
index 00000000..f5aa3d1b
Binary files /dev/null and b/HelloSerial4j/shared/native/Linux/linux-x86-x64/libserial4j.so differ
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/errno/Errno.java b/HelloSerial4j/src/main/java/com/serial4j/core/errno/Errno.java
new file mode 100644
index 00000000..7f3e6133
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/errno/Errno.java
@@ -0,0 +1,119 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.errno;
+
+import com.serial4j.core.serial.NativeTerminalDevice;
+
+/**
+ * Interprets the native methods bad return values into error codes,
+ * used by the java {@link com.serial4j.core.errno.ErrnoToException}
+ * to throw exceptions against the JRE.
+ *
+ * @author pavl_g.
+ */
+public enum Errno {
+ /**
+ * Serial4j business errors.
+ */
+ ERR_INVALID_PORT(NativeErrno.getInvalidPortErrno(), "Invalid Port"),
+ ERR_OPERATION_FAILED(NativeErrno.getOperationFailedErrno(), "Operation Failed"),
+ ERR_NO_AVAILABLE_TTY_DEVICES(NativeErrno.getNoAvailableTtyDevicesErrno(), "No available teletype devices"),
+
+ /**
+ * Error codes for open(const char*, int), file names and IO.
+ */
+ EACCES(NativeErrno.getPermissionDeniedErrno(), "Permission denied"),
+ EEXIST(NativeErrno.getFileAlreadyOpenedErrno(), "File exists"),
+ EINTR(NativeErrno.getInterruptedSystemCallErrno(), "Interrupted system call"),
+ EISDIR(NativeErrno.getFileIsDirectoryErrno(), "Is a directory"),
+ EMFILE(NativeErrno.getTooManyOpenedFilesErrno(), "Too many open files"),
+ ENFILE(NativeErrno.getFileTableOverflowErrno(), "File table overflow"),
+ ENOENT(NativeErrno.getNoSuchFileErrno(), "No Such file or directory"),
+ ENOSPC(NativeErrno.getNoSpaceLeftErrno(), "No space left on device"),
+ ENXIO(NativeErrno.getNoSuchDeviceErrno(), "No such device or address"),
+ EROFS(NativeErrno.getReadOnlyFileSystemErrno(), "Read-only file system"),
+ EPIPE(NativeErrno.getBrokenPipeErrno(), "Broken pipe"),
+
+ /**
+ * Error codes for tcgetattr(int, struct termios*) and tcsetattr(int, struct termios*).
+ */
+ EBADF(NativeErrno.getBadFileDescriptorErrno(), "File descriptor in bad state"),
+ ENOTTY(NativeErrno.getNotTtyDeviceErrno(), "Not a typewriter device"),
+
+ /**
+ * tcsetattr(int, struct termios*) only.
+ */
+ EINVAL(NativeErrno.getInvalidArgumentErrno(), "Invalid argumnet"),
+
+ /**
+ * Additional error codes for basic R/W from
+ */
+ EAGAIN(NativeErrno.getTryAgainErrno(), "Try again"),
+ EIO(NativeErrno.getInputOutputErrno(), "I/O Error"),
+
+ /**
+ * For write(int, void*, int); only.
+ */
+ EFBIG(NativeErrno.getFileTooLargeErrno(), "File too large");
+
+ private final int value;
+ private final String description;
+
+ /**
+ * Creates an error code constant with a value and a description.
+ *
+ * @param value the errno value.
+ * @param description the errno description.
+ */
+ Errno(final int value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ /**
+ * Gets the native error code of the Err.
+ *
+ * @return an integer reference to the error code.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Gets the native error code descritption.
+ *
+ * @return the error code description in String format.
+ */
+ public String getDescription() {
+ return description;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/errno/ErrnoToException.java b/HelloSerial4j/src/main/java/com/serial4j/core/errno/ErrnoToException.java
new file mode 100644
index 00000000..6163ef85
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/errno/ErrnoToException.java
@@ -0,0 +1,124 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.errno;
+
+import com.serial4j.core.serial.throwable.PermissionDeniedException;
+import com.serial4j.core.serial.throwable.BadFileDescriptorException;
+import com.serial4j.core.serial.throwable.FileAlreadyOpenedException;
+import com.serial4j.core.serial.throwable.FileIsDirectoryException;
+import com.serial4j.core.serial.throwable.FileTableOverflowException;
+import com.serial4j.core.serial.throwable.FileTooLargeException;
+import com.serial4j.core.serial.throwable.InputOutputException;
+import com.serial4j.core.serial.throwable.InterruptedSystemCallException;
+import com.serial4j.core.serial.throwable.ErrnoNotFoundError;
+import com.serial4j.core.serial.throwable.NoSuchFileException;
+import com.serial4j.core.serial.throwable.InvalidArgumentException;
+import com.serial4j.core.serial.throwable.NoSpaceLeftException;
+import com.serial4j.core.serial.throwable.ReadOnlyFileSystemException;
+import com.serial4j.core.serial.throwable.NotTtyDeviceException;
+import com.serial4j.core.serial.throwable.TooManyOpenedFilesException;
+import com.serial4j.core.serial.throwable.TryAgainException;
+import com.serial4j.core.serial.throwable.BrokenPipeException;
+import com.serial4j.core.serial.throwable.NoSuchDeviceException;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+import com.serial4j.core.serial.throwable.OperationFailedException;
+import com.serial4j.core.serial.throwable.NoAvailableTtyDevicesException;
+import com.serial4j.core.errno.Errno;
+
+/**
+ * Reflects C native errnos into real java exceptions.
+ *
+ * @author pavl_g.
+ */
+public final class ErrnoToException {
+
+ private ErrnoToException() {
+ }
+
+ /**
+ * Throws a java exception from a native errno.
+ *
+ * @param errno the native error code to which the exception will be thrown against.
+ * @param additionalText additional text in string format to be displayed within the throwable message.
+ *
+ * @throws NoSuchDeviceException in case of errno(2).
+ * @throws PermissionDeniedException in case of errno(13).
+ * @throws BrokenPipeException in case of errno(32).
+ * @throws InvalidPortException in case of errno(-2).
+ * @throws OperationFailedException in case of errno(-1).
+ * @throws NoAvailableTtyDevicesException in case of errno(-4).
+ */
+ public static void throwFromErrno(final int errno, final String additionalText) {
+ if (errno == Errno.ENOENT.getValue()) {
+ throw new NoSuchFileException(additionalText);
+ } else if (errno == Errno.EACCES.getValue()) {
+ throw new PermissionDeniedException(additionalText);
+ } else if (errno == Errno.EPIPE.getValue()) {
+ throw new BrokenPipeException(additionalText);
+ } else if (errno == Errno.ERR_INVALID_PORT.getValue()) {
+ throw new InvalidPortException(additionalText);
+ } else if (errno == Errno.ERR_NO_AVAILABLE_TTY_DEVICES.getValue()) {
+ throw new NoAvailableTtyDevicesException(additionalText);
+ } else if (errno == Errno.EBADF.getValue()) {
+ throw new BadFileDescriptorException(additionalText);
+ } else if (errno == Errno.EEXIST.getValue()) {
+ throw new FileAlreadyOpenedException(additionalText);
+ } else if (errno == Errno.EISDIR.getValue()) {
+ throw new FileIsDirectoryException(additionalText);
+ } else if (errno == Errno.ENFILE.getValue()) {
+ throw new FileTableOverflowException(additionalText);
+ } else if (errno == Errno.EFBIG.getValue()) {
+ throw new FileTooLargeException(additionalText);
+ } else if (errno == Errno.EIO.getValue()) {
+ throw new InputOutputException(additionalText);
+ } else if (errno == Errno.EINTR.getValue()) {
+ throw new InterruptedSystemCallException(additionalText);
+ } else if (errno == Errno.EINVAL.getValue()) {
+ throw new InvalidArgumentException(additionalText);
+ } else if (errno == Errno.ENOSPC.getValue()) {
+ throw new NoSpaceLeftException(additionalText);
+ } else if (errno == Errno.ENXIO.getValue()) {
+ throw new NoSuchDeviceException(additionalText);
+ } else if (errno == Errno.EROFS.getValue()) {
+ throw new ReadOnlyFileSystemException(additionalText);
+ } else if (errno == Errno.ENOTTY.getValue()) {
+ throw new NotTtyDeviceException(additionalText);
+ } else if (errno == Errno.EMFILE.getValue()) {
+ throw new TooManyOpenedFilesException(additionalText);
+ } else if (errno == Errno.EAGAIN.getValue()) {
+ throw new TryAgainException(additionalText);
+ } else {
+ throw new ErrnoNotFoundError("Cannot interpret this error code !");
+ }
+ }
+
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/errno/NativeErrno.java b/HelloSerial4j/src/main/java/com/serial4j/core/errno/NativeErrno.java
new file mode 100644
index 00000000..259cea3a
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/errno/NativeErrno.java
@@ -0,0 +1,47 @@
+package com.serial4j.core.errno;
+
+public final class NativeErrno {
+
+ private NativeErrno() {
+ }
+
+ protected static native int getBadFileDescriptorErrno();
+
+ protected static native int getBrokenPipeErrno();
+
+ protected static native int getFileAlreadyOpenedErrno();
+
+ protected static native int getFileIsDirectoryErrno();
+
+ protected static native int getFileTableOverflowErrno();
+
+ protected static native int getFileTooLargeErrno();
+
+ protected static native int getInputOutputErrno();
+
+ protected static native int getInterruptedSystemCallErrno();
+
+ protected static native int getInvalidArgumentErrno();
+
+ protected static native int getInvalidPortErrno();
+
+ protected static native int getNoAvailableTtyDevicesErrno();
+
+ protected static native int getNoSpaceLeftErrno();
+
+ protected static native int getNoSuchDeviceErrno();
+
+ protected static native int getNoSuchFileErrno();
+
+ protected static native int getNotTtyDeviceErrno();
+
+ protected static native int getOperationFailedErrno();
+
+ protected static native int getPermissionDeniedErrno();
+
+ protected static native int getReadOnlyFileSystemErrno();
+
+ protected static native int getTooManyOpenedFilesErrno();
+
+ protected static native int getTryAgainErrno();
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/errno/package-info.java b/HelloSerial4j/src/main/java/com/serial4j/core/errno/package-info.java
new file mode 100644
index 00000000..47bec615
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/errno/package-info.java
@@ -0,0 +1,37 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Provides a native errno to java exception converter {@link ErrnoToException} and {@link Errno} for
+ * native errno interpretation.
+ */
+package com.serial4j.core.errno;
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/BaudRate.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/BaudRate.java
new file mode 100644
index 00000000..36bfdea3
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/BaudRate.java
@@ -0,0 +1,129 @@
+/*
+ * termios type and macro definitions. Linux version.
+ * Copyright (C) 1993-2019 Free Software Foundation, Inc.
+ * This file is part of the GNU C Library.
+ *
+ * The GNU C Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; if not, see
+ * .
+ *
+ * -----------------------------------------------------------------------
+ *
+ * BSD 3-Clause License for Serial4j from the AVR-Sandbox Project.
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+/**
+ * Represents codes for the POSIX Systems baud rates and their real values
+ * defined from <./usr/include/x86_64-linux-gnu/bits/termios.h>.
+ *
+ * @author pavl_g.
+ */
+public enum BaudRate {
+
+ /** Baudrates for POSIX systems as defined by */
+ B0(0000000, 0),
+ B50(0000001, 50),
+ B75(0000002, 75),
+ B110(0000003, 110),
+ B134(0000004, 134),
+ B150(0000005, 150),
+ B200(0000006, 200),
+ B300(0000007, 300),
+ B600(0000010, 600),
+ B1200(0000011, 1200),
+ B1800(0000012, 1800),
+ B2400(0000013, 2400),
+ B4800(0000014, 4800),
+ B9600(0000015, 9600),
+ B19200(0000016, 19200),
+ B38400(0000017, 38400),
+ B57600(0010001, 57600),
+ B115200(0010002, 115200),
+ B230400(0010003, 230400),
+ B460800(0010004, 460800),
+ B500000(0010005, 500000),
+ B576000(0010006, 576000),
+ B921600(0010007, 921600),
+ B1000000(0010010, 1000000),
+ B1152000(0010011, 1152000),
+ B1500000(0010012, 1500000),
+ B2000000(0010013, 2000000),
+ B2500000(0010014, 2500000),
+ B3000000(0010015, 3000000),
+ B3500000(0010016, 3500000),
+ B4000000(0010017, 4000000),
+ MAX_BAUD(B4000000.getBaudRate(), B4000000.getRealBaud());
+
+ private final int baudRate;
+ private final long realBaud;
+
+ /**
+ * Defines a basic structure for POSIX baud rates.
+ *
+ * @param baudRate the baud rate representative POSIX code.
+ * @param realBaud the real baud value.
+ */
+ BaudRate(final int baudRate, final long realBaud) {
+ this.baudRate = baudRate;
+ this.realBaud = realBaud;
+ }
+
+ /**
+ * Retrieves the real baud rate value from the baud
+ * rate structure defined by the POSIX code.
+ *
+ * @return the real baud rate.
+ */
+ public long getRealBaud() {
+ return realBaud;
+ }
+
+ /**
+ * Retrieves the baud rate code defined from for
+ * POSIX systems.
+ *
+ * @return the code for this baud rate.
+ */
+ public int getBaudRate() {
+ return baudRate;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/NativeTerminalDevice.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/NativeTerminalDevice.java
new file mode 100644
index 00000000..1f140a28
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/NativeTerminalDevice.java
@@ -0,0 +1,334 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+import com.serial4j.core.serial.SerialPort;
+import com.serial4j.core.util.natives.NativeImageLoader;
+
+/**
+ * Represents the native java binding for Serial4j API, represented by
+ * [com_serial4j_core_serial_NativeTerminalDevice.h] natively.
+ *
+ * @author pavl_g.
+ */
+public final class NativeTerminalDevice {
+
+ /**
+ * Static initializer: Loads the native image when this object is created or referenced.
+ */
+ static {
+ NativeImageLoader.loadLibrary();
+ }
+
+ private SerialPort serialPort;
+ private String[] serialPorts;
+ private char[] readData;
+ private String readBuffer = new String();
+
+ protected NativeTerminalDevice() {
+ }
+
+ /**
+ * Initializes the serial port path of the native terminal device before opening the terminal device port.
+ *
+ * @param serialPort the object to initialize the serial port with.
+ */
+ protected void setSerialPort(final SerialPort serialPort) {
+ this.serialPort = serialPort;
+ }
+
+ /**
+ * Retrieves the serial port associated with this terminal device.
+ *
+ * @return the serial port object associated with this terminal device.
+ */
+ public SerialPort getSerialPort() {
+ return this.serialPort;
+ }
+
+ /**
+ * Retrieves all the available teletype terminal (tty) devices from the filesystem "/dev".
+ *
+ * @return the available tty devices in an array of strings format.
+ */
+ public String[] getSerialPorts() {
+ return this.serialPorts;
+ }
+
+ /**
+ * Gets the read data in an up-to 32-bit integer format resulting from using the native method {@link NativeTerminalDevice#readData0()}.
+ *
+ * @return the read data from this terminal device in an up-to 32-bit integer format.
+ */
+ public char[] getReadData() {
+ return this.readData;
+ }
+
+ public String getReadBuffer() {
+ return this.readBuffer;
+ }
+
+ /**
+ * Sets up the native environment for this terminal device.
+ *
+ * @return (-1) if the jni env pointer is NULL, (1) for successful initialization.
+ */
+ protected static native int setupJniEnvironment0();
+
+ /**
+ * Adjusts the native terminal control [c_cflag] of the [termios] structure variable for this terminal device.
+ * @apiNote The terminal control flag controls the way the terminal device r/w the charachters on the console.
+ * For more, refer to the POSIX terminal control guide.
+ *
+ * Default value = tty->c_cflag |= (CREAD | CS8 | CLOCAL); defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @param flag the flag to set the [c_cflag] to.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ * @see com.serial4j.core.serial.control.TerminalControlFlag
+ */
+ protected native int setTerminalControlFlag(final long flag);
+
+ /**
+ * Adjusts the native terminal local [c_lflag] of the [termios] structure variable for this terminal device.
+ * @apiNote The terminal local flag controls the way the terminal device interprets and displays the charachters on the console (i.e local console).
+ * For more, refer to the POSIX terminal control guide.
+ *
+ * Default value = tty->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT | ECHOCTL | ISIG | IEXTEN);
+ * defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @param flag the flag to set the [c_lflag] to.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ * @see com.serial4j.core.serial.control.TerminalLocalFlag
+ */
+ protected native int setTerminalLocalFlag(final long flag);
+
+ /**
+ * Adjusts the native terminal input [c_iflag] of the [termios] structure variable for this terminal device.
+ * @apiNote The terminal input flag controls the way the terminal device receives and interprets the charachters on input.
+ * For more, refer to the POSIX terminal control guide.
+ *
+ * Default value = tty->c_iflag = 0x00; defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @param flag the flag to set the [c_iflag] to.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ * @see com.serial4j.core.serial.control.TerminalInputFlag
+ */
+ protected native int setTerminalInputFlag(final long flag);
+
+ /**
+ * Adjusts the native terminal output [c_oflag] of the [termios] structure variable for this terminal device.
+ * @apiNote The terminal output flag controls the way the terminal device transmits and interprets the charachters on output.
+ * For more, refer to the POSIX terminal control guide.
+ *
+ * Default value = tty->c_oflag &= ~(OPOST | ONLCR); defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @param flag the flag to set the [c_oflag] to.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ * @see com.serial4j.core.serial.control.TerminalOutputFlag
+ */
+ protected native int setTerminalOutputFlag(final long flag);
+
+ /**
+ * Retrieves the terminal control flag from this terminal device port descriptor in 64-bit format.
+ *
+ * @return the [c_cflag] value in longs.
+ */
+ protected native long getTerminalControlFlag();
+
+ /**
+ * Retrieves the terminal local flag from this terminal device port descriptor in 64-bit format.
+ *
+ * @return the [c_lflag] value in longs.
+ */
+ protected native long getTerminalLocalFlag();
+
+ /**
+ * Retrieves the terminal input flag from this terminal device port descriptor in 64-bit format.
+ *
+ * @return the [c_iflag] value in longs.
+ */
+ protected native long getTerminalInputFlag();
+
+ /**
+ * Retrieves the terminal output flag from this terminal device port descriptor in 64-bit format.
+ *
+ * @return the [c_oflag] value in longs.
+ */
+ protected native long getTerminalOutputFlag();
+
+ /**
+ * Adjusts the read mode for this terminal device, the read mode is defined by the read timeout value and the minimum
+ * number of bytes to read at that time.
+ *
+ * Default value = BLOCKING_READ_ONE_CHAR {0, 1}; defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @param mode the read mode in a 2 lengthed array format, where first index refers to the timeout config and second index
+ * refers to the bytes config.
+ * @param VTIME_VALUE the value of the read timeout, applied only when the first index of [mode] is 1 (aka read timeout is activated).
+ * @param VMIN_VALUE the value of the minimum byte to read in this time.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ * @see com.serial4j.core.serial.ReadConfiguration
+ */
+ protected native int setReadConfigurationMode0(final int VTIME_VALUE, final int VMIN_VALUE);
+
+ /**
+ * Gets the read configuration for this terminal device defining the timeout value as the first index and
+ * the minimum number of read byte in this timeout as the second index.
+ *
+ * Default value = BLOCKING_READ_ONE_CHAR {0, 1}; defined by {@link NativeTerminalDevice#initTermios0()}.
+ *
+ * @return an array refering to the read mode, where index [0] represents the read timeout, index [1] represents
+ * the minimum bytes to read.
+ */
+ protected native int[] getReadConfigurationMode0();
+
+ /**
+ * Retrieves the last error encountered by the native code,
+ *
+ * @return the last error code from the native .
+ */
+ protected native int getErrno0();
+
+ /**
+ * Fetches the available system teletype terminal devices (tty) located within "/dev" directory
+ * and insert the result into {@link NativeTerminalDevice#serialPorts}.
+ *
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ */
+ protected native int fetchSerialPorts0();
+
+ /**
+ * Retrieves the baud rate POSIX code for this terminal process, find more at <./usr/include/x86_64-linux-gnu/bits/termios.h>.
+ *
+ * @return the baud rate code in integers.
+ */
+ protected native int getBaudRate0();
+
+ /**
+ * Writes an integer buffer to this terminal device.
+ *
+ * @param data an integer data buffer to write up-to 32-bit.
+ * @return the number of written bytes in long format.
+ */
+ protected native long writeData0(final int data);
+
+ /**
+ * Reads the data from the terminal device and inserts the result into an integer buffer
+ * {@link NativeTerminalDevice#readData}.
+ *
+ * @return the number of read bytes.
+ */
+ protected native long readData0();
+
+ /**
+ * Writes a string buffer (const char*) with a length to this terminal device.
+ *
+ * @param buffer a string buffer to write to this terminal device.
+ * @param length the string buffer length in integers, this minimizes the jni native calls.
+ * @return the number of written bytes to this terminal device.
+ */
+ protected native long writeBuffer0(final String buffer, final int length);
+
+ /**
+ * Reads the data from this terminal device and insert the result into the {@link NativeTerminalDevice#readBuffer}
+ * string buffer.
+ *
+ * @return the number of read bytes from this terminal device.
+ */
+ protected native long readBuffer0();
+
+ /**
+ * Opens this terminal device using the path to the port [port] in strings and the port permissions [flag] in integers.
+ *
+ * @param port the port path in strings.
+ * @param int the flag for the base file control native api [fcntl].
+ * @return errno(-1) for failure, errno(1) for success.
+ */
+ protected native int openPort0(final String port, final int flag);
+
+ /**
+ * Initializes this terminal device with the default terminal flags and read timeout properties:
+ * -----------
+ * # c_cflag: for control mode flags.
+ * *** Enable these bits:
+ * - [CREAD]: Allow input to be received.
+ * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value.
+ * - [CLOCAL]: Ignore modem status lines (donÂ’t check carrier signal).
+ * -----------
+ * # c_lflag: for local mode flags.
+ * ***Disable these bits:
+ * - [ICANON]: Canonical mode (line-by-line) input.
+ * - [ECHO]: Echo input characters.
+ * - [ECHOE]: Perform ERASE visually.
+ * - [ECHOK]: Echo KILL visually.
+ * - [ECHOKE]: DonÂ’t output a newline after echoed KILL.
+ * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled.
+ * - [ECHOPRT]: Echo deleted characters backward (between \ and / ).
+ * - [ECHOCTL]: Echo control characters visually (e.g., ^L ).
+ * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP).
+ * - [IEXTEN]: Enable extended processing of input characters.
+ * -----------
+ * # c_oflag: for output mode flags.
+ * ***Disable these bits:
+ * - [OPOST]: Perform output postprocessing.
+ * - [ONLCR]: Map NL to CR-NL on output.
+ * -----------
+ * # c_iflag: for input mode flags.
+ * ***Disable all input bit masks.
+ * -----------
+ * # c_cc: For control characters.
+ * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE.
+ * -----------
+ *
+ * @apiNote This should be called right after {@link NativeTerminalDevice#openPort0(String, int)}.
+ *
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ */
+ protected native int initTermios0();
+
+ /**
+ * Adjusts the baud rate aka. the speed of data transmission in bits/seconds for this bus.
+ *
+ * @param baudRate the baud rate POSIX native code, find more about baud rate codes at <./usr/include/x86_64-linux-gnu/bits/termios.h>.
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ */
+ protected native int setBaudRate0(int baudRate);
+
+ /**
+ * Closes the serial port of this terminal device releasing the resources.
+ * @apiNote This call triggers {@link NativeTerminalDevice#serialPort#portOpened} to 0,
+ * the port descriptor {@link NativeTerminalDevice#serialPort#fd} to 0 and the port path {@link NativeTerminalDevice#serialPort#fd} to "".
+ *
+ * @return errno(-1) for failure, errno(-2) for invalid port, errno(1) for success.
+ */
+ protected native int closePort0();
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/Permissions.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/Permissions.java
new file mode 100644
index 00000000..9558f7c6
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/Permissions.java
@@ -0,0 +1,135 @@
+/*
+ * From POSIX Standard: 6.5 File Control Operations.
+ * Copyright (C) 1993-2019 Free Software Foundation, Inc.
+ * This file is part of the GNU C Library.
+ *
+ * The GNU C Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * The GNU C Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; if not, see
+ * .
+ *
+ * -----------------------------------------------------------------------
+ *
+ * BSD 3-Clause License for Serial4j from the AVR-Sandbox Project.
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+/**
+ * Provides Unix file system permissions for the specified serial port
+ * of the terminal device.
+ *
+ * @author pavl_g.
+ */
+public final class Permissions {
+
+ public static final Permissions O_RDONLY = new Permissions(00, "Read Only");
+ public static final Permissions O_WRONLY = new Permissions(01, "Write Only");
+ public static final Permissions O_RDWR = new Permissions(02, "Read/Write");
+ public static final Permissions O_NOCTTY = new Permissions(0400, "No Control terminal device");
+ public static final Permissions O_NONBLOCK = new Permissions(04000, "Terminal non block");
+
+ private int value;
+ private String description;
+
+ /**
+ * Wraps a POSIX IO flag using an integer value.
+ *
+ * @param value the value of the permission flag.
+ * @param description the description of the flag.
+ */
+ protected Permissions(final int value, final String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ /**
+ * Create a custom permissions object from a source value.
+ *
+ * @param value the value of the permission flag.
+ * @param description the description for this flag.
+ * @return a new Permissions object wrapping the POSIX IO flag.
+ */
+ public static final Permissions createCustomPermissions(final int value, final String description) {
+ return new Permissions(value, description);
+ }
+
+ /**
+ * Appends new permissions to this permissions object.
+ *
+ * @param permissions the new permissions to append.
+ * @return this permissions object with the new appended value.
+ */
+ public Permissions append(final Permissions permissions) {
+ this.value |= permissions.getValue();
+ this.description += "-" + permissions.getDescription();
+ return this;
+ }
+
+ /**
+ * Appends some new permissions to this permissions object.
+ *
+ * @param permissions an array args of the new permissions to append.
+ * @return this permissions object with the new appended value.
+ */
+ public Permissions append(final Permissions...permissions) {
+ for (int i = 0; i < permissions.length; i++) {
+ append(permissions[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Retrieves the value of this permissions object.
+ *
+ * @return the value of this permissions object.
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Retrieves the description of this permissions object.
+ *
+ * @return the description of this permissions object.
+ */
+ public String getDescription() {
+ return description;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/ReadConfiguration.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/ReadConfiguration.java
new file mode 100644
index 00000000..e159ecbb
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/ReadConfiguration.java
@@ -0,0 +1,84 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+import java.util.Arrays;
+import com.serial4j.core.errno.Errno;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+
+/**
+ * Provides a Unix terminal read configuration for the specified serial port of the
+ * terminal device.
+ *
+ * @author pavl_g.
+ */
+public enum ReadConfiguration {
+ POLLING_READ(new int[] {0, 0}, "Polling Read"),
+ BLOCKING_READ_ONE_CHAR(new int[] {0, 1}, "Blocking read one charachter at a time"),
+ READ_WITH_TIMEOUT(new int[] {1, 0}, "Polling Read with timeout"),
+ READ_WITH_INTERBYTE_TIMEOUT(new int[] {1, 1}, "Blocking read with timeout"),
+ ERR_INVALID_PORT(new int[] {(int) Errno.ERR_INVALID_PORT.getValue(), (int) Errno.ERR_INVALID_PORT.getValue()}, "Error invalid port");
+
+ private int[] mode;
+ private final String description;
+
+ ReadConfiguration(final int[] mode, final String description) {
+ this.mode = mode;
+ this.description = description;
+ }
+
+ public int[] getMode() {
+ return mode;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public static ReadConfiguration getFromNativeReadConfig(final int[] nativeReadConfig) {
+ ReadConfiguration readConfiguration;
+ if (nativeReadConfig[0] < 1 && nativeReadConfig[1] >= 1) {
+ readConfiguration = ReadConfiguration.BLOCKING_READ_ONE_CHAR;
+ } else if ((nativeReadConfig[0] | nativeReadConfig[1]) == 0) {
+ readConfiguration = ReadConfiguration.POLLING_READ;
+ } else if (nativeReadConfig[0] >= 1 && nativeReadConfig[1] >= 1) {
+ readConfiguration = ReadConfiguration.READ_WITH_INTERBYTE_TIMEOUT;
+ } else if ((nativeReadConfig[0] & nativeReadConfig[1]) == Errno.ERR_INVALID_PORT.getValue()) {
+ throw new InvalidPortException("Cannot get read configuration for an invalid port !");
+ } else {
+ readConfiguration = ReadConfiguration.READ_WITH_TIMEOUT;
+ }
+ /* update the mode value with the native readConfig value */
+ readConfiguration.mode = nativeReadConfig;
+ return readConfiguration;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/SerialPort.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/SerialPort.java
new file mode 100644
index 00000000..2d9bdd50
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/SerialPort.java
@@ -0,0 +1,95 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+/**
+ * Represents a Unix terminal device port properties wrapper.
+ *
+ * @author pavl_g.
+ */
+public final class SerialPort {
+
+ private String path;
+ private int portOpened;
+ private int fd;
+ private int ioFlag;
+
+ /**
+ * Instantiates a new serial port for a terminal device with a port path.
+ * The rest of the port data is assigned from the jni side after opening the device.
+ *
+ * @param path the port path on the file system.
+ */
+ public SerialPort(final String path) {
+ this.path = path;
+ }
+
+ /**
+ * Gets the io flags defined by the {@link com.serial4j.core.serial.Permissions}.
+ * The io flags setter is assigned from the jni side by {@link com.serial4j.core.serial.NativeTerminalDevice#openPort(String, int)}.
+ *
+ * @return a number format representing the IO flag for the POSIX base file api.
+ */
+ public int getIOFlag() {
+ return ioFlag;
+ }
+
+ /**
+ * Gets the path to this port.
+ *
+ * @return a String representing the path to this port.
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Gets the virtual file descriptor defining this port.
+ * The fd (file descriptor) setter is assigned from the jni side by {@link com.serial4j.core.serial.NativeTerminalDevice#openPort(String, int)}.
+ *
+ * @return a number format representing the file descriptor for this port.
+ */
+ public int getFd() {
+ return fd;
+ }
+
+ /**
+ * Tests whether this port is still opened.
+ * This flag setter is assigned from the jni side by {@link com.serial4j.core.serial.NativeTerminalDevice#openPort(String, int)}
+ * and {@link com.serial4j.core.serial.NativeTerminalDevice#closePort()}.
+ *
+ * @return true if the port is still alive, false if the port is closed.
+ */
+ public boolean isPortOpened() {
+ return this.portOpened == 1;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/TerminalDevice.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/TerminalDevice.java
new file mode 100644
index 00000000..28bf8d45
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/TerminalDevice.java
@@ -0,0 +1,499 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import com.serial4j.core.errno.Errno;
+import com.serial4j.core.util.natives.NativeImageLoader;
+import com.serial4j.core.serial.Permissions;
+import com.serial4j.core.errno.ErrnoToException;
+import com.serial4j.core.serial.SerialPort;
+import com.serial4j.core.serial.NativeTerminalDevice;
+import com.serial4j.core.serial.ReadConfiguration;
+import com.serial4j.core.serial.control.TerminalControlFlag;
+import com.serial4j.core.serial.control.TerminalLocalFlag;
+import com.serial4j.core.serial.control.TerminalInputFlag;
+import com.serial4j.core.serial.control.TerminalOutputFlag;
+import com.serial4j.core.serial.throwable.PermissionDeniedException;
+import com.serial4j.core.serial.throwable.BrokenPipeException;
+import com.serial4j.core.serial.throwable.NoSuchDeviceException;
+import com.serial4j.core.serial.throwable.TooManyOpenedFilesException;
+import com.serial4j.core.serial.throwable.ReadOnlyFileSystemException;
+import com.serial4j.core.serial.throwable.FileAlreadyOpenedException;
+import com.serial4j.core.serial.throwable.BadFileDescriptorException;
+import com.serial4j.core.serial.throwable.NotTtyDeviceException;
+import com.serial4j.core.serial.throwable.InvalidArgumentException;
+import com.serial4j.core.serial.throwable.FileIsDirectoryException;
+import com.serial4j.core.serial.throwable.InterruptedSystemCallException;
+import com.serial4j.core.serial.throwable.FileTableOverflowException;
+import com.serial4j.core.serial.throwable.NoSuchFileException;
+import com.serial4j.core.serial.throwable.NoSpaceLeftException;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+import com.serial4j.core.serial.throwable.NoAvailableTtyDevicesException;
+
+/**
+ * The main entry class for the native terminal device for Serial4j api.
+ *
+ * @author pavl_g.
+ */
+public final class TerminalDevice {
+
+ /**
+ * Static initializer for loading and setting up the native image.
+ * This initializer has a static context and therefore it runs only one
+ * time when creating the first object.
+ */
+ static {
+ NativeImageLoader.loadLibrary();
+ TerminalDevice.setupJniEnvironment();
+ }
+
+ private static final Logger LOGGER = Logger.getLogger(TerminalDevice.class.getName());
+ private final NativeTerminalDevice nativeTerminalDevice = new NativeTerminalDevice();
+
+ private Permissions permissions = Permissions.O_RDWR.append(Permissions.O_NOCTTY)
+ .append(Permissions.O_NONBLOCK);
+ private ReadConfiguration readConfiguration;
+ private String permissionsDescription;
+ private boolean loggingEnabled;
+ private InputStream inputStream;
+ private OutputStream outputStream;
+
+ /**
+ * Instantiates a Unix terminal device object.
+ */
+ public TerminalDevice() {
+
+ }
+
+ /**
+ * Sets up the jvm pointer from jni environment pointer on the heap for the global
+ * multithreaded reference.
+ *
+ * @apiNote Native and jvm threads can access the jni pointer from the global jvm pointer without
+ * referencing one of the local jni env pointers stored on another thread stack (as this leads to a thread-transition error).
+ */
+ private static void setupJniEnvironment() {
+ final int errno = NativeTerminalDevice.setupJniEnvironment0();
+ ErrnoToException.throwFromErrno(errno, "Jni Environment passed is invalid !");
+ }
+
+ /**
+ * Opens this device's serial port using the path from [serialPort] instance.
+ *
+ * @param serialPort the serial port instance to open.
+ *
+ * @throws NoSuchDeviceException if an attempt is made to open a non-device file.
+ * @throws NoSuchFileException if an attempt is made to access a file that doesn't exist.
+ * @throws FileAlreadyOpenedException if an attempt is made to open an already opened terminal device.
+ * @throws InterruptedSystemCallException if there is a process interruption while opening the port.
+ * @throws FileIsDirectoryException if an attempt is made to open a directory instead of a device.
+ * @throws TooManyOpenedFilesException if an attempt is made to open too many devices exceeding the system limit.
+ * @throws FileTableOverflowException if an attempt is made to open a device while system io is halt.
+ * @throws NoSpaceLeftException if an attempt is made to open a device while there is no space left.
+ * @throws ReadOnlyFileSystemException if an attempt is made to open a read-only device.
+ * @throws PermissionDeniedException if an unauthorized user attempts to open this device.
+ */
+ public void openPort(final SerialPort serialPort) throws NoSuchDeviceException,
+ NoSuchFileException,
+ FileAlreadyOpenedException,
+ InterruptedSystemCallException,
+ FileIsDirectoryException,
+ TooManyOpenedFilesException,
+ FileTableOverflowException,
+ NoSpaceLeftException,
+ ReadOnlyFileSystemException,
+ PermissionDeniedException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Opening serial device " + serialPort.getPath());
+ }
+ this.nativeTerminalDevice.setSerialPort(serialPort);
+ final int returnValue = nativeTerminalDevice.openPort0(serialPort.getPath(), permissions.getValue());
+ if (isOperationFailed(returnValue)) {
+ ErrnoToException.throwFromErrno(nativeTerminalDevice.getErrno0(), serialPort.getPath());
+ }
+ /* update port data natively */
+ /* ... */
+ }
+
+ /**
+ * Initializes this terminal device with the default flags and the default
+ * read timeout configuration.
+ *
+ * @throws InvalidPortException if an attempt is made to initialize an invalid port (non-opened/still-closed device).
+ * @throws FileNotFoundException if the device opened before has been ejected.
+ * @throws NoAvailableTtyDevicesException if the port is closed while performing the initialization operation.
+ */
+ public void initTermios() throws InvalidPortException,
+ FileNotFoundException,
+ NoAvailableTtyDevicesException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Initializing serial device " + getSerialPort().getPath());
+ }
+ int returnValue = nativeTerminalDevice.initTermios0();
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ /* get the java streams from the port after initializing it with the native terminal */
+ inputStream = new FileInputStream(getSerialPort().getPath());
+ outputStream = new FileOutputStream(getSerialPort().getPath());
+ }
+
+ /**
+ * Adjusts the terminal control flag of the termios, the terminal control flag controls the
+ * characters behavior in the local terminal.
+ *
+ * @param flag the terminal control flag to adjust.
+ * @throws BadFileDescriptorException if the filedes is not a valid file descriptor.
+ * @throws InvalidPortException if the port is null or has not been initialized yet.
+ * @throws NotTtyDeviceException if the filedes is not associated with a terminal device.
+ * @throws InvalidArgumentException if the value of the when argument is not valid,
+ * or there is something wrong with the data in the termios-p argument.
+ */
+ public void setTerminalControlFlag(final TerminalControlFlag flag) throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException,
+ InvalidArgumentException {
+
+ int returnValue = nativeTerminalDevice.setTerminalControlFlag(flag.getValue());
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ }
+
+ /**
+ * Adjusts the terminal local flag of the termios, the terminal local flag controls how the
+ * terminal interprets the characters on the local console.
+ *
+ * @param flag the local flag to adjust.
+ * @throws BadFileDescriptorException if the filedes is not a valid file descriptor.
+ * @throws InvalidPortException if the port is null or has not been initialized yet.
+ * @throws NotTtyDeviceException if the filedes is not associated with a terminal device.
+ * @throws InvalidArgumentException if the value of the when argument is not valid,
+ * or there is something wrong with the data in the termios-p argument.
+ */
+ public void setTerminalLocalFlag(final TerminalLocalFlag flag) throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException,
+ InvalidArgumentException {
+ int returnValue = nativeTerminalDevice.setTerminalLocalFlag(flag.getValue());
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ }
+
+ /**
+ * Adjusts the terminal input flag for the termios, the terminal input flag controls how
+ * the terminal interpret the characters at the input from the terminal device.
+ *
+ * @param flag the terminal input flag to adjust.
+ * @throws BadFileDescriptorException if the filedes is not a valid file descriptor.
+ * @throws InvalidPortException if the port is null or has not been initialized yet.
+ * @throws NotTtyDeviceException if the filedes is not associated with a terminal device.
+ * @throws InvalidArgumentException if the value of the when argument is not valid,
+ * or there is something wrong with the data in the termios-p argument.
+ */
+ public void setTerminalInputFlag(final TerminalInputFlag flag) throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException,
+ InvalidArgumentException {
+ int returnValue = nativeTerminalDevice.setTerminalInputFlag(flag.getValue());
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ }
+
+ /**
+ * Adjusts the terminal output flag for this terminal device, the terminal output flag controls
+ * how the terminal interpret the charachters at the output to the terminal device.
+ *
+ * @throws BadFileDescriptorException if the filedes is not a valid file descriptor.
+ * @throws InvalidPortException if the port is null or has not been initialized yet.
+ * @throws NotTtyDeviceException if the filedes is not associated with a terminal device.
+ * @throws InvalidArgumentException if the value of the when argument is not valid,
+ * or there is something wrong with the data in the termios-p argument.
+ */
+ public void setTerminalOutputFlag(final TerminalOutputFlag flag) throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException,
+ InvalidArgumentException {
+ int returnValue = nativeTerminalDevice.setTerminalOutputFlag(flag.getValue());
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ }
+
+ public TerminalControlFlag getTerminalControlFlag() throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException {
+ final TerminalControlFlag TCF = TerminalControlFlag.EMPTY_INSTANCE;
+ final long returnValue = nativeTerminalDevice.getTerminalControlFlag();
+ /* Warning: Force cast the errno to (int) */
+ ErrnoToException.throwFromErrno((int) returnValue, getSerialPort().getPath());
+ TCF.setValue(returnValue);
+ return TCF;
+ }
+
+ public TerminalLocalFlag getTerminalLocalFlag() throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException {
+ final TerminalLocalFlag TLF = TerminalLocalFlag.EMPTY_INSTANCE;
+ final long returnValue = nativeTerminalDevice.getTerminalLocalFlag();
+ /* Warning: Force cast the errno to (int) */
+ ErrnoToException.throwFromErrno((int) returnValue, getSerialPort().getPath());
+ TLF.setValue(returnValue);
+ return TLF;
+ }
+
+ public TerminalInputFlag getTerminalInputFlag() throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException {
+ final TerminalInputFlag TIF = TerminalInputFlag.EMPTY_INSTANCE;
+ final long returnValue = nativeTerminalDevice.getTerminalInputFlag();
+ /* Warning: Force cast the errno to (int) */
+ ErrnoToException.throwFromErrno((int) returnValue, getSerialPort().getPath());
+ TIF.setValue(returnValue);
+ return TIF;
+ }
+
+ public TerminalOutputFlag getTerminalOutputFlag() throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException {
+ final TerminalOutputFlag TOF = TerminalOutputFlag.EMPTY_INSTANCE;
+ final long returnValue = nativeTerminalDevice.getTerminalOutputFlag();
+ /* Warning: Force cast the errno to (int) */
+ ErrnoToException.throwFromErrno((int) returnValue, getSerialPort().getPath());
+ TOF.setValue(returnValue);
+ return TOF;
+ }
+
+ public void setPermissions(final Permissions permissions) {
+ this.permissions = permissions;
+ }
+
+ public final Permissions getPermissions() {
+ return permissions;
+ }
+
+ public void setBaudRate(final BaudRate baudRate) throws BadFileDescriptorException,
+ InvalidPortException,
+ NotTtyDeviceException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Setting device baud rate to " + baudRate.getRealBaud());
+ }
+ int returnValue = nativeTerminalDevice.setBaudRate0(baudRate.getBaudRate());
+ if (isOperationFailed(returnValue)) {
+ returnValue = nativeTerminalDevice.getErrno0();
+ }
+ ErrnoToException.throwFromErrno(returnValue, getSerialPort().getPath());
+ }
+
+ public void setReadConfigurationMode(final ReadConfiguration readConfiguration, final int timeoutValue, final int minimumBytes) throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Setting reading config to " + readConfiguration.getDescription());
+ }
+ final int timoutByteValue = readConfiguration.getMode()[0] * timeoutValue;
+ final int minimumBytesValue = readConfiguration.getMode()[1] * minimumBytes;
+ final int errno = nativeTerminalDevice.setReadConfigurationMode0(Math.min(255, timoutByteValue), Math.min(255, minimumBytesValue));
+ ErrnoToException.throwFromErrno(errno, "port is not invalid.");
+ }
+
+ public final ReadConfiguration getReadConfigurationMode() {
+ return ReadConfiguration.getFromNativeReadConfig(nativeTerminalDevice.getReadConfigurationMode0());
+ }
+
+ public final long writeBuffer(final String buffer) throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ final long numberOfWrittenBytes = nativeTerminalDevice.writeBuffer0(buffer, buffer.length());
+ String message;
+ if (numberOfWrittenBytes == -1) {
+ message = "Write Permission [O_WRONLY] isnot granted, [Permissions: " + permissionsDescription + "]";
+ } else {
+ message = "Invalid Port " + nativeTerminalDevice.getSerialPort().getPath();
+ }
+ if (numberOfWrittenBytes < 1) {
+ ErrnoToException.throwFromErrno(nativeTerminalDevice.getErrno0(), message);
+ }
+ return numberOfWrittenBytes;
+ }
+
+ public long writeData(final int data) throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ final long numberOfWrittenBytes = nativeTerminalDevice.writeData0(data);
+ String message;
+ if (numberOfWrittenBytes == -1) {
+ message = "Write Permission [O_WRONLY] isnot granted.";
+ } else {
+ message = "Invalid Port " + nativeTerminalDevice.getSerialPort().getPath();
+ }
+ if (numberOfWrittenBytes < 0) {
+ ErrnoToException.throwFromErrno(nativeTerminalDevice.getErrno0(), message);
+ }
+ return numberOfWrittenBytes;
+ }
+
+ public long writeData(final int[] data) throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ long numberOfWrittenBytes = 0;
+ for (int i = 0; i < data.length; i++) {
+ numberOfWrittenBytes += this.writeData(data[i]);
+ if (numberOfWrittenBytes < 0) {
+ break;
+ }
+ }
+ return numberOfWrittenBytes;
+ }
+
+ public final long readData() {
+ return nativeTerminalDevice.readData0();
+ }
+
+ public final long readBuffer() {
+ return nativeTerminalDevice.readBuffer0();
+ }
+
+ public final String getReadBuffer() {
+ return nativeTerminalDevice.getReadBuffer();
+ }
+
+ public final int getBaudRate() throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Getting device baud");
+ }
+ final int errno = nativeTerminalDevice.getBaudRate0();
+ ErrnoToException.throwFromErrno(errno, getSerialPort().getPath());
+ return errno;
+ }
+
+ public final String[] getSerialPorts() throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ fetchSerialPorts();
+ return nativeTerminalDevice.getSerialPorts();
+ }
+
+ public void throwExceptionFromNativeErrno() throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ final int errno = nativeTerminalDevice.getErrno0();
+ ErrnoToException.throwFromErrno(errno, "Native Errno: " + errno);
+ }
+
+ public void closePort() throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Closing port: " + getSerialPort().getPath());
+ }
+ final int errno = nativeTerminalDevice.closePort0();
+ ErrnoToException.throwFromErrno(errno, getSerialPort().getPath());
+ }
+
+ public void setSerial4jLoggingEnabled(final boolean loggingEnabled) {
+ this.loggingEnabled = loggingEnabled;
+ }
+
+ public final boolean isSerial4jLoggingEnabled() {
+ return loggingEnabled;
+ }
+
+ public final char[] getReadData() {
+ return nativeTerminalDevice.getReadData();
+ }
+
+ public final InputStream getInputStream() {
+ return inputStream;
+ }
+
+ public final OutputStream getOutputStream() {
+ return outputStream;
+ }
+
+ public final SerialPort getSerialPort() {
+ return nativeTerminalDevice.getSerialPort();
+ }
+
+ private void fetchSerialPorts() throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ NoAvailableTtyDevicesException {
+ if (isSerial4jLoggingEnabled()) {
+ LOGGER.log(Level.INFO, "Fetching Serial ports.");
+ }
+ final int errno = nativeTerminalDevice.fetchSerialPorts0();
+ ErrnoToException.throwFromErrno(errno, "No available devices !");
+ }
+
+ private boolean isOperationFailed(final int returnValue) {
+ return returnValue == Errno.ERR_OPERATION_FAILED.getValue();
+ }
+
+ private boolean isErrnoAvailable(final int errno) {
+ return errno > 0;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalControlFlag.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalControlFlag.java
new file mode 100644
index 00000000..e0865989
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalControlFlag.java
@@ -0,0 +1,54 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.control;
+
+public final class TerminalControlFlag extends TerminalFlag {
+
+ public static final TerminalControlFlag EMPTY_INSTANCE = new TerminalControlFlag(0);
+ public static final TerminalControlFlag CIBAUD = new TerminalControlFlag(002003600000);
+ public static final TerminalControlFlag CS5 = new TerminalControlFlag(0000000);
+ public static final TerminalControlFlag CS6 = new TerminalControlFlag(0000020);
+ public static final TerminalControlFlag CS7 = new TerminalControlFlag(0000040);
+ public static final TerminalControlFlag CS8 = new TerminalControlFlag(0000060);
+ public static final TerminalControlFlag CLOCAL = new TerminalControlFlag(0004000);
+ public static final TerminalControlFlag CREAD = new TerminalControlFlag(0000200);
+ public static final TerminalControlFlag CMSPAR = new TerminalControlFlag(010000000000);
+ public static final TerminalControlFlag CRTSCTS = new TerminalControlFlag(020000000000);
+ public static final TerminalControlFlag CSTOPB = new TerminalControlFlag(0000100);
+ public static final TerminalControlFlag HUPCL = new TerminalControlFlag(0002000);
+ public static final TerminalControlFlag PARENB = new TerminalControlFlag(0000400);
+ public static final TerminalControlFlag PARODD = new TerminalControlFlag(0001000);
+
+ protected TerminalControlFlag(final long value) {
+ super(value);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalFlag.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalFlag.java
new file mode 100644
index 00000000..a1104961
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalFlag.java
@@ -0,0 +1,138 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.control;
+
+import java.lang.Long;
+
+/**
+ * Represents the base implementation for the termios.h terminal flags values.
+ *
+ * @author pavl_g.
+ */
+public abstract class TerminalFlag {
+
+ private long value;
+
+ /**
+ * Instantiates a termios flag with a value to be settled from the native side.
+ * @param value the value of the termios flag.
+ */
+ protected TerminalFlag(final long value) {
+ this.value = value;
+ }
+
+ /**
+ * Appends a flag's value into the current one's value.
+ *
+ * @param flag a flag to append to this instance.
+ * @return this flag instance for chained append.
+ */
+ public TerminalFlag append(final TerminalFlag flag) {
+ this.value |= flag.getValue();
+ return this;
+ }
+
+ /**
+ * Disables a flag from the current one value.
+ *
+ * @param flag a flag to disable.
+ * @return this flag instance for chained call.
+ */
+ public TerminalFlag disable(final TerminalFlag flag) {
+ this.value &= ~flag.getValue();
+ return this;
+ }
+
+ /**
+ * Appends a list of flags' values into the current one's value.
+ *
+ * @param flags an args representing the flags list to append.
+ * @return this flag instance for chained append.
+ */
+ public TerminalFlag append(final TerminalFlag...flags) {
+ for (int i = 0; i < flags.length; i++) {
+ append(flags[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Disables a list of flags from the current flag instance.
+ *
+ * @param flags flags to disable.
+ * @return this flag instance for chained call.
+ */
+ public TerminalFlag disable(final TerminalFlag...flags) {
+ for (int i = 0; i < flags.length; i++) {
+ disable(flags[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Enables all the terminal flags for this instance.
+ *
+ * @return this instance for chained call.
+ */
+ public TerminalFlag enableAll() {
+ this.value = Long.MAX_VALUE;
+ return this;
+ }
+
+ /**
+ * Disables all the terminal flags for this instance.
+ *
+ * @return this instance for chained call.
+ */
+ public TerminalFlag disableAll() {
+ this.value = 0;
+ return this;
+ }
+
+ /**
+ * Gets the value of the specified termios flag.
+ *
+ * @return the value of the terminal flag.
+ */
+ public long getValue() {
+ return value;
+ }
+
+ /**
+ * Adjusts the value of the specified termios flag.
+ *
+ * @param value the value of the terminal flag.
+ */
+ public void setValue(final long value) {
+ this.value = value;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalInputFlag.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalInputFlag.java
new file mode 100644
index 00000000..85203de0
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalInputFlag.java
@@ -0,0 +1,59 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.control;
+
+/**
+ * Provides Unix [c_iflag] termios bits.
+ *
+ * @author pavl_g.
+ */
+public final class TerminalInputFlag extends TerminalFlag {
+
+ public static final TerminalInputFlag EMPTY_INSTANCE = new TerminalInputFlag(0);
+ public static final TerminalInputFlag BRKINT = new TerminalInputFlag(0000002);
+ public static final TerminalInputFlag ICRNL = new TerminalInputFlag(0000400);
+ public static final TerminalInputFlag IGNBRK = new TerminalInputFlag(0000001);
+ public static final TerminalInputFlag IGNCR = new TerminalInputFlag(0000200);
+ public static final TerminalInputFlag IMAXBEL = new TerminalInputFlag(0020000);
+ public static final TerminalInputFlag INLCR = new TerminalInputFlag(0000100);
+ public static final TerminalInputFlag INPCK = new TerminalInputFlag(0000020);
+ public static final TerminalInputFlag ISTRIP = new TerminalInputFlag(0000040);
+ public static final TerminalInputFlag IUTF8 = new TerminalInputFlag(0040000);
+ public static final TerminalInputFlag IXANY = new TerminalInputFlag(0004000);
+ public static final TerminalInputFlag IXOFF = new TerminalInputFlag(0010000);
+ public static final TerminalInputFlag IXON = new TerminalInputFlag(0002000);
+ public static final TerminalInputFlag PARMRK = new TerminalInputFlag(0000010);
+
+ protected TerminalInputFlag(final long value) {
+ super(value);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalLocalFlag.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalLocalFlag.java
new file mode 100644
index 00000000..3542addd
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalLocalFlag.java
@@ -0,0 +1,56 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.control;
+
+public final class TerminalLocalFlag extends TerminalFlag {
+
+ public static final TerminalLocalFlag EMPTY_INSTANCE = new TerminalLocalFlag(0);
+ public static final TerminalLocalFlag ECHO = new TerminalLocalFlag(0000010);
+ public static final TerminalLocalFlag ECHOCTL = new TerminalLocalFlag(0001000);
+ public static final TerminalLocalFlag ECHOE = new TerminalLocalFlag(0000020);
+ public static final TerminalLocalFlag ECHOK = new TerminalLocalFlag(0000040);
+ public static final TerminalLocalFlag ECHOKE = new TerminalLocalFlag(0004000);
+ public static final TerminalLocalFlag ECHONL = new TerminalLocalFlag(0000100);
+ public static final TerminalLocalFlag ECHOPRT = new TerminalLocalFlag(0002000);
+ public static final TerminalLocalFlag FLUSHO = new TerminalLocalFlag(0010000);
+ public static final TerminalLocalFlag ICANON = new TerminalLocalFlag(0000002);
+ public static final TerminalLocalFlag IEXTEN = new TerminalLocalFlag(0100000);
+ public static final TerminalLocalFlag ISIG = new TerminalLocalFlag(0000001);
+ public static final TerminalLocalFlag NOFLSH = new TerminalLocalFlag(0000200);
+ public static final TerminalLocalFlag PENDIN = new TerminalLocalFlag(0040000);
+ public static final TerminalLocalFlag TOSTOP = new TerminalLocalFlag(0000400);
+ public static final TerminalLocalFlag XCASE = new TerminalLocalFlag(0000004);
+
+ protected TerminalLocalFlag(final long value) {
+ super(value);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalOutputFlag.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalOutputFlag.java
new file mode 100644
index 00000000..79c9c65d
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/control/TerminalOutputFlag.java
@@ -0,0 +1,65 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.control;
+
+public final class TerminalOutputFlag extends TerminalFlag {
+
+ public static final TerminalOutputFlag EMPTY_INSTANCE = new TerminalOutputFlag(0);
+ public static final TerminalOutputFlag BS0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag BS1 = new TerminalOutputFlag(0020000);
+ public static final TerminalOutputFlag CR0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag CR1 = new TerminalOutputFlag(0001000);
+ public static final TerminalOutputFlag CR2 = new TerminalOutputFlag(0002000);
+ public static final TerminalOutputFlag CR3 = new TerminalOutputFlag(0003000);
+ public static final TerminalOutputFlag FF0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag FF1 = new TerminalOutputFlag(0100000);
+ public static final TerminalOutputFlag NL0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag NL1 = new TerminalOutputFlag(0000400);
+ public static final TerminalOutputFlag OCRNL = new TerminalOutputFlag(0000010);
+ public static final TerminalOutputFlag OFDEL = new TerminalOutputFlag(0000200);
+ public static final TerminalOutputFlag OFILL = new TerminalOutputFlag(0000100);
+ public static final TerminalOutputFlag OLCUC = new TerminalOutputFlag(0000002);
+ public static final TerminalOutputFlag ONLCR = new TerminalOutputFlag(0000004);
+ public static final TerminalOutputFlag ONLRET = new TerminalOutputFlag(0000040);
+ public static final TerminalOutputFlag ONOCR = new TerminalOutputFlag(0000020);
+ public static final TerminalOutputFlag OPOST = new TerminalOutputFlag(0000001);
+ public static final TerminalOutputFlag TAB0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag TAB1 = new TerminalOutputFlag(0004000);
+ public static final TerminalOutputFlag TAB2 = new TerminalOutputFlag(0010000);
+ public static final TerminalOutputFlag TAB3 = new TerminalOutputFlag(0014000);
+ public static final TerminalOutputFlag VT0 = new TerminalOutputFlag(0000000);
+ public static final TerminalOutputFlag VT1 = new TerminalOutputFlag(0040000);
+
+ protected TerminalOutputFlag(final long value) {
+ super(value);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/EntityStatus.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/EntityStatus.java
new file mode 100644
index 00000000..8743000e
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/EntityStatus.java
@@ -0,0 +1,64 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.entity;
+
+/**
+ * Represents the serial entity status listener.
+ *
+ * @param generic type for the {@link SerialMonitorEntity} type, either {@link serial.entity.impl.SerialWriteEntity}
+ * or {@link serial.entity.impl.SerialReadEntity}.
+ *
+ * @author pavl_g.
+ */
+public interface EntityStatus {
+
+ /**
+ * Fired when the serial entity is initialized on the first monitor update.
+ *
+ * @param serialMonitorEntity the serial entity object.
+ */
+ void onSerialEntityInitialized(final T serialMonitorEntity);
+
+ /**
+ * Fired when the serial entity is terminated on the last monitor update.
+ *
+ * @param serialMonitorEntity the serial entity object.
+ */
+ void onSerialEntityTerminated(final T serialMonitorEntity);
+
+ /**
+ * Fired on each serial monitor update.
+ *
+ * @param serialMonitorEntity the serial entity object.
+ */
+ void onUpdate(final T serialMonitorEntity);
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/SerialMonitorEntity.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/SerialMonitorEntity.java
new file mode 100644
index 00000000..22b3af27
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/SerialMonitorEntity.java
@@ -0,0 +1,216 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.entity;
+
+import com.serial4j.core.serial.TerminalDevice;
+import com.serial4j.core.serial.monitor.SerialDataListener;
+import com.serial4j.core.serial.monitor.SerialMonitor;
+import com.serial4j.core.util.process.Semaphore;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * Represents the base implementation for serial monitor Read and Write entities.
+ * @see serial.entity.impl.SerialWriteEntity
+ * @see serial.entity.impl.SerialReadEntity
+ *
+ * @author pavl_g.
+ */
+public abstract class SerialMonitorEntity implements Runnable {
+
+ protected final Semaphore.Mutex MUTEX = new Semaphore.Mutex();
+ protected final Semaphore SEMAPHORE = Semaphore.build(MUTEX);
+
+ private final Logger entityLogger;
+ private boolean hasLoggedMonitor;
+ private final SerialMonitor serialMonitor;
+ private final String entityName;
+
+ /**
+ * Defines a serial monitor basic entity.
+ *
+ * @param serialMonitor the monitor object.
+ * @param entityName the entity name.
+ */
+ public SerialMonitorEntity(SerialMonitor serialMonitor, String entityName) {
+ this.serialMonitor = serialMonitor;
+ this.entityName = entityName;
+
+ entityLogger = Logger.getLogger(entityName);
+ initMutexWithLockData();
+ }
+
+ @Override
+ public void run() {
+ /* using re-entrant block to be optimized by the new vthreads system */
+ SEMAPHORE.lock(this);
+ if (!hasLoggedMonitor) {
+ entityLogger.log(Level.INFO, "Started data monitoring for " + entityName + " thread " + Thread.currentThread());
+ }
+ onDataMonitored(getSerialMonitor());
+ SEMAPHORE.unlock(this);
+ }
+
+ /**
+ * Terminates this entity by closing the entity stream and the serial port.
+ */
+ protected void terminate() {
+ try {
+ getEntityStream().close();
+ hasLoggedMonitor = false;
+ entityLogger.log(Level.WARNING, "Terminated data monitoring for " + entityName + " thread " + Thread.currentThread());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ synchronized (SerialMonitorEntity.class) {
+ if (getTerminalDevice().getSerialPort().isPortOpened()) {
+ try {
+ getTerminalDevice().closePort();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /**
+ * Tests whether return carriage [\n\r] and new line is enabled.
+ *
+ * @return true if [\n\r] check is enabled, default value is [true].
+ */
+ protected boolean isUsingReturnCarriage() {
+ return getSerialMonitor().isUsingReturnCarriage();
+ }
+
+ /**
+ * Tests whether serial data monitoring has started.
+ *
+ * @return true if data monitor has started, default value is [false].
+ */
+ protected boolean isMonitoringStarted() {
+ return getSerialMonitor().isMonitoringStarted;
+ }
+
+ /**
+ * Sets the monitor started state.
+ *
+ * @param state true to indicate the monitor has started and to start the data
+ * writing, false otherwise.
+ */
+ protected void setMonitoringStarted(boolean state) {
+ getSerialMonitor().isMonitoringStarted = state;
+ }
+
+ /**
+ * Retrieves the {@link SerialMonitor} instance.
+ *
+ * @return the serial monitor object that holds this entity.
+ */
+ public SerialMonitor getSerialMonitor() {
+ return serialMonitor;
+ }
+
+ /**
+ * Retrieves the {@link TerminalDevice} instance used for creating the communication.
+ *
+ * @return a serial port instance.
+ */
+ protected TerminalDevice getTerminalDevice() {
+ return getSerialMonitor().getTerminalDevice();
+ }
+
+ /**
+ * Retrieves the serial data listeners list.
+ *
+ * @return a list instance representing the serial data listeners.
+ */
+ protected ArrayList getSerialDataListeners() {
+ return getSerialMonitor().getSerialDataListeners();
+ }
+
+ /**
+ * Tests whether the serial monitor holding this entity terminated.
+ * @see SerialMonitor#setTerminate()
+ *
+ * @return true if the serial monitor has been terminated by the user, default value is false.
+ */
+ protected boolean isTerminate() {
+ return getSerialMonitor().isTerminate();
+ }
+
+ /**
+ * Fired on each update run.
+ *
+ * @param serialMonitor the serial monitor that holds this entity.
+ */
+ protected abstract void onDataMonitored(final SerialMonitor serialMonitor);
+
+ /**
+ * Gets the entity status listener.
+ *
+ * @return the serial entity status listener.
+ */
+ protected abstract EntityStatus extends SerialMonitorEntity> getSerialEntityStatusListener();
+
+ /**
+ * Tests whether the entity is initialized.
+ *
+ * @return true if the serial entity has been initialized, false otherwise, default value is false.
+ */
+ protected abstract boolean isSerialEntityInitialized();
+
+ /**
+ * Sets the serial entity initialized status.
+ *
+ * @see SerialMonitor#isReadSerialEntityInitialized
+ * @see SerialMonitor#isWriteSerialEntityInitialized
+ *
+ * @param state a state to set.
+ */
+ protected abstract void setSerialEntityInitialized(boolean state);
+
+ /**
+ * Gets the entity stream provided by the {@link SerialPort}, either {@link java.io.OutputStream}
+ * or {@link java.io.InputStream}.
+ *
+ * @return a stream provided by the SerialPort.
+ */
+ protected abstract Closeable getEntityStream();
+
+ private void initMutexWithLockData() {
+ MUTEX.setLockData(this);
+ MUTEX.setMonitorObject(this);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialReadEntity.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialReadEntity.java
new file mode 100644
index 00000000..3743258c
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialReadEntity.java
@@ -0,0 +1,143 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.entity.impl;
+
+import com.serial4j.core.serial.entity.EntityStatus;
+import com.serial4j.core.serial.entity.SerialMonitorEntity;
+import com.serial4j.core.serial.monitor.SerialMonitor;
+import com.serial4j.core.serial.monitor.SerialMonitorException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Represents a Read entity for the {@link SerialMonitor}.
+ * Use {@link SerialMonitor#startDataMonitoring(String, int)} to start this entity.
+ *
+ * @author pavl_g.
+ */
+public class SerialReadEntity extends SerialMonitorEntity {
+
+ private StringBuffer stringBuffer = new StringBuffer();
+
+ /**
+ * Defines a read entity instance to read serial data from UART.
+ * Use {@link SerialMonitor#startDataMonitoring(String, int)} to start this entity.
+ *
+ * @param serialMonitor the head serial monitor object.
+ */
+ public SerialReadEntity(final SerialMonitor serialMonitor) {
+ super(serialMonitor, SerialReadEntity.class.getName());
+ }
+
+ @Override
+ protected void onDataMonitored(SerialMonitor serialMonitor) {
+ for (; ; ) {
+ /* throws if not initialized yet */
+ if (getTerminalDevice() == null) {
+ throw new SerialMonitorException(SerialMonitorException.DEFAULT_MSG);
+ }
+
+ /* sanity check [terminate] flag */
+ if (isTerminate()) {
+ terminate();
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onSerialEntityTerminated(this);
+ }
+ return;
+ }
+
+ if (!isSerialEntityInitialized()) {
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onSerialEntityInitialized(this);
+ }
+ setSerialEntityInitialized(true);
+ }
+
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onUpdate(this);
+ }
+
+ /* execute serial data tasks */
+ for (int i = 0; i < getSerialDataListeners().size(); i++) {
+ try {
+ final int count = getEntityStream().available();
+ if (count != 0) {
+ final char data = (char) getEntityStream().read();
+
+ /* send characters serially */
+ getSerialDataListeners().get(i).onDataReceived(data);
+
+ /* get a string buffer from a data frame */
+ /* send data frames separated by [\n\r] the return carriage/newline */
+ stringBuffer.append(data);
+
+ if (isUsingReturnCarriage()) {
+ if (stringBuffer.toString().contains("\n\r")) {
+ getSerialDataListeners().get(i).onDataReceived(stringBuffer.toString());
+ stringBuffer = new StringBuffer();
+ }
+ } else {
+ getSerialDataListeners().get(i).onDataReceived(stringBuffer.toString());
+ stringBuffer = new StringBuffer();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (!isMonitoringStarted()) {
+ setMonitoringStarted(true);
+ }
+ }
+ }
+
+ @Override
+ protected InputStream getEntityStream() {
+ return getSerialMonitor().getReadEntityStream();
+ }
+
+ @Override
+ protected boolean isSerialEntityInitialized() {
+ return getSerialMonitor().isReadSerialEntityInitialized;
+ }
+
+ @Override
+ protected void setSerialEntityInitialized(final boolean state) {
+ getSerialMonitor().isReadSerialEntityInitialized = state;
+ }
+
+ @Override
+ protected EntityStatus getSerialEntityStatusListener() {
+ return getSerialMonitor().serialReadEntityEntityStatus;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialWriteEntity.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialWriteEntity.java
new file mode 100644
index 00000000..9dcce97b
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/SerialWriteEntity.java
@@ -0,0 +1,177 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.entity.impl;
+
+import com.serial4j.core.serial.entity.EntityStatus;
+import com.serial4j.core.serial.entity.SerialMonitorEntity;
+import com.serial4j.core.serial.monitor.SerialMonitor;
+import com.serial4j.core.serial.monitor.SerialMonitorException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+/**
+ * Represents a serial write data entity for the {@link SerialMonitor}.
+ * Use {@link SerialMonitor#startDataMonitoring(String, int)} to start this entity.
+ *
+ * @author pavl_g.
+ */
+public class SerialWriteEntity extends SerialMonitorEntity {
+
+ private final ArrayList writableCapsules = new ArrayList<>();
+
+ public SerialWriteEntity(final SerialMonitor serialMonitor) {
+ super(serialMonitor, SerialWriteEntity.class.getName());
+ }
+
+ @Override
+ protected void onDataMonitored(SerialMonitor serialMonitor) {
+ for (; ; ) {
+ /* throws if not initialized yet */
+ if (getTerminalDevice() == null) {
+ throw new SerialMonitorException(SerialMonitorException.DEFAULT_MSG);
+ }
+
+ /* sanity check [terminate] flag */
+ if (isTerminate()) {
+ terminate();
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onSerialEntityTerminated(this);
+ }
+ return;
+ }
+
+ /* sanity check data monitoring status */
+ if (!isMonitoringStarted()) {
+ continue;
+ }
+
+ /* initialize and update serial entity */
+ if (!isSerialEntityInitialized()) {
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onSerialEntityInitialized(this);
+ }
+ setSerialEntityInitialized(true);
+ }
+
+ if (getSerialEntityStatusListener() != null) {
+ getSerialEntityStatusListener().onUpdate(this);
+ }
+
+ /* write required data */
+ for (WritableCapsule capsule : writableCapsules) {
+ /* skip capsules with written data */
+ if (capsule.isDataWritten()) {
+ continue;
+ }
+ /* send capsule data to the UART */
+ final String data = capsule.getData();
+ for (int j = 0; j < data.length(); j++) {
+ sendToUART(data.charAt(j));
+ for (int k = 0; k < getSerialDataListeners().size(); k++) {
+ getSerialDataListeners().get(k).onDataTransmitted(data.charAt(j));
+ }
+ }
+ capsule.setDataWritten(true);
+ }
+ }
+ }
+
+ @Override
+ protected OutputStream getEntityStream() {
+ return getSerialMonitor().getWriteEntityStream();
+ }
+
+ @Override
+ protected boolean isSerialEntityInitialized() {
+ return getSerialMonitor().isWriteSerialEntityInitialized;
+ }
+
+ @Override
+ protected void setSerialEntityInitialized(boolean state) {
+ getSerialMonitor().isWriteSerialEntityInitialized = state;
+ }
+
+ @Override
+ protected EntityStatus getSerialEntityStatusListener() {
+ return getSerialMonitor().serialWriteEntityEntityStatus;
+ }
+
+ /**
+ * Gets the Serial writable Capsules holding the writable data.
+ *
+ * @return an array list of the writable capsules.
+ */
+ public ArrayList getSerialWriteCapsules() {
+ return writableCapsules;
+ }
+
+ /**
+ * Adds a new writable capsule, the data will be extracted during the
+ * next update run.
+ *
+ * @param writableCapsule a new {@link WritableCapsule} to add.
+ */
+ public synchronized void addWritableCapsule(final WritableCapsule writableCapsule) {
+ if (writableCapsules.contains(writableCapsule)) {
+ return;
+ }
+ writableCapsules.add(writableCapsule);
+ }
+
+ /**
+ * Removes a writable capsule from the list of serial data capsules.
+ *
+ * @param writableCapsule an instance of the {@link WritableCapsule}.
+ */
+ public void removeWritableCapsule(final WritableCapsule writableCapsule) {
+ if (!writableCapsules.contains(writableCapsule)) {
+ return;
+ }
+ writableCapsules.remove(writableCapsule);
+ }
+
+ /**
+ * Internal-Use-Only.
+ *
+ * Sends data to the {@link OutputStream} of {@link com.fazecast.jSerialComm.SerialPort}.
+ *
+ * @param data the data to send in integers.
+ */
+ private void sendToUART(final int data) {
+ try {
+ getEntityStream().write(data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/WritableCapsule.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/WritableCapsule.java
new file mode 100644
index 00000000..778bd5c9
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/WritableCapsule.java
@@ -0,0 +1,81 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.entity.impl;
+
+/**
+ * Represents a serial write capsule for the {@link SerialWriteEntity}.
+ *
+ * @author pavl_g.
+ */
+public final class WritableCapsule implements Cloneable {
+
+ private String data;
+ private boolean dataWritten;
+
+ /**
+ * Specifies the data to be written on the next update of the
+ * SerialWriteEntity.
+ *
+ * @param data the data to be written to the UART.
+ */
+ public void write(final String data) {
+ this.data = data;
+ }
+
+ /**
+ * Retrieves the data of the capsule.
+ *
+ * @return the data in string.
+ */
+ public String getData() {
+ return data;
+ }
+
+ /**
+ * Tests whether data is written to the UART.
+ *
+ * @return true if the data is written to the UART, false otherwise.
+ */
+ public boolean isDataWritten() {
+ return dataWritten;
+ }
+
+ /**
+ * Sets the flag for data write to the serial UART, where; true commands and
+ * stops the data write to the serial UART, false otherwise.
+ *
+ * @param dataWritten true to keep writing data in the next update, false otherwise.
+ */
+ public void setDataWritten(boolean dataWritten) {
+ this.dataWritten = dataWritten;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/package-info.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/package-info.java
new file mode 100644
index 00000000..97c74d89
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/impl/package-info.java
@@ -0,0 +1,39 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * An implementation code for {@link serial.entity.SerialMonitorEntity} providing both read and
+ * write serial monitor entities.
+ *
+ * @author pavl_g.
+ */
+package com.serial4j.core.serial.entity.impl;
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/package-info.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/package-info.java
new file mode 100644
index 00000000..259b49bf
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/entity/package-info.java
@@ -0,0 +1,38 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Provides R/W serial monitor entities with a subscriber pattern.
+ *
+ * @author pavl_g.
+ */
+package com.serial4j.core.serial.entity;
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialDataListener.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialDataListener.java
new file mode 100644
index 00000000..d6c4d1d3
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialDataListener.java
@@ -0,0 +1,70 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.monitor;
+
+/**
+ * Listens to Serial Monitor entities {@link serial.entity.impl.SerialReadEntity} and {@link serial.entity.impl.SerialWriteEntity}.
+ *
+ * @author pavl_g.
+ */
+public interface SerialDataListener {
+
+ /**
+ * Dispatched when the data is received at the {@link serial.entity.impl.SerialReadEntity} end
+ * on its thread.
+ *
+ * This method is dispatched on the {@link serial.entity.impl.SerialReadEntity} thread.
+ *
+ * @param data the data received serially in 8-bit format.
+ */
+ void onDataReceived(final int data);
+
+ /**
+ * Dispatched when the capsular data is transmitted at the {@link serial.entity.impl.SerialWriteEntity}
+ * end on its thread.
+ *
+ * This method is dispatched on the {@link serial.entity.impl.SerialWriteEntity} thread.
+ *
+ * @param data the data transmitted serially in 8-bit format.
+ */
+ void onDataTransmitted(final int data);
+
+ /**
+ * Dispatched whenever a data frame is completely received at the {@link serial.entity.impl.SerialReadEntity} end
+ * when [Return-Carriage/Newline] check is enabled as it specifies a particular data frame.
+ *
+ * This method is dispatched on the {@link serial.entity.impl.SerialReadEntity} thread.
+ *
+ * @param data the data frame.
+ */
+ void onDataReceived(final String data);
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitor.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitor.java
new file mode 100644
index 00000000..533ff021
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitor.java
@@ -0,0 +1,291 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.monitor;
+
+import com.serial4j.core.serial.control.TerminalControlFlag;
+import com.serial4j.core.serial.control.TerminalLocalFlag;
+import com.serial4j.core.serial.control.TerminalOutputFlag;
+import com.serial4j.core.serial.control.TerminalInputFlag;
+import com.serial4j.core.serial.ReadConfiguration;
+import com.serial4j.core.serial.Permissions;
+import com.serial4j.core.serial.BaudRate;
+import com.serial4j.core.serial.SerialPort;
+import com.serial4j.core.serial.TerminalDevice;
+import com.serial4j.core.serial.throwable.PermissionDeniedException;
+import com.serial4j.core.serial.throwable.NoAvailableTtyDevicesException;
+import com.serial4j.core.serial.throwable.BrokenPipeException;
+import com.serial4j.core.serial.throwable.NoSuchDeviceException;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+import com.serial4j.core.serial.throwable.OperationFailedException;
+import com.serial4j.core.serial.entity.impl.SerialReadEntity;
+import com.serial4j.core.serial.entity.impl.SerialWriteEntity;
+import com.serial4j.core.serial.entity.EntityStatus;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+/**
+ * Monitors the UART Data Port using {@link SerialReadEntity} for serial data read and {@link SerialWriteEntity} for serial
+ * data write.
+ *
+ * @author pavl_g.
+ */
+public final class SerialMonitor {
+
+ private final ArrayList serialDataListeners = new ArrayList<>();
+ private final String monitorName;
+
+ public volatile EntityStatus serialReadEntityEntityStatus;
+ public volatile EntityStatus serialWriteEntityEntityStatus;
+ public volatile boolean isReadSerialEntityInitialized;
+ public volatile boolean isWriteSerialEntityInitialized;
+ public volatile boolean isMonitoringStarted;
+ public volatile boolean useReturnCarriage = true;
+
+ private volatile InputStream readEntityStream;
+ private volatile OutputStream writeEntityStream;
+ private volatile TerminalDevice terminalDevice;
+ private volatile boolean terminate = false;
+ private volatile SerialReadEntity serialReadEntity;
+ private volatile SerialWriteEntity serialWriteEntity;
+
+ /**
+ * Instantiates a new SerialMonitor with a name.
+ *
+ * Use {@link SerialMonitor#startDataMonitoring(String, int)} to initialize and start
+ * data monitoring.
+ *
+ * @param monitorName the name for this monitor.
+ */
+ public SerialMonitor(final String monitorName) {
+ this.monitorName = monitorName;
+ }
+
+ /**
+ * Initializes and starts data monitoring on a [port] and with a [baudRate]
+ *
+ * @param port specify the serial port.
+ * @param baudRate specify the baud rate aka bits/seconds based for the connected FOsc.
+ */
+ public void startDataMonitoring(final String port, final BaudRate baudRate, final Permissions permissions) throws NoSuchDeviceException,
+ PermissionDeniedException,
+ BrokenPipeException,
+ InvalidPortException,
+ OperationFailedException,
+ NoAvailableTtyDevicesException,
+ FileNotFoundException {
+ /* ignore timeout strategy */
+ terminalDevice = new TerminalDevice();
+ terminalDevice.setSerial4jLoggingEnabled(true);
+ if (permissions != null) {
+ terminalDevice.setPermissions(permissions);
+ }
+ terminalDevice.openPort(new SerialPort(port));
+ terminalDevice.setBaudRate(baudRate);
+ terminalDevice.initTermios();
+ /* define terminal flags */
+ final TerminalControlFlag TCF_VALUE = (TerminalControlFlag) TerminalControlFlag.CLOCAL
+ .append(TerminalControlFlag.CS8, TerminalControlFlag.CREAD);
+ final TerminalLocalFlag TLF_VALUE = (TerminalLocalFlag) TerminalLocalFlag.EMPTY_INSTANCE
+ .disable(TerminalLocalFlag.ECHO, TerminalLocalFlag.ECHOK,
+ TerminalLocalFlag.ECHOE, TerminalLocalFlag.ECHOKE,
+ TerminalLocalFlag.ECHONL, TerminalLocalFlag.ECHOPRT,
+ TerminalLocalFlag.ECHOCTL, TerminalLocalFlag.ISIG,
+ TerminalLocalFlag.IEXTEN, TerminalLocalFlag.ICANON);
+ final TerminalOutputFlag TOF_VALUE = (TerminalOutputFlag) TerminalOutputFlag.EMPTY_INSTANCE
+ .disable(TerminalOutputFlag.OPOST, TerminalOutputFlag.ONLCR);
+ final TerminalInputFlag TIF_VALUE = (TerminalInputFlag) TerminalInputFlag.EMPTY_INSTANCE.disableAll();
+
+ terminalDevice.setTerminalControlFlag(TCF_VALUE);
+ terminalDevice.setTerminalLocalFlag(TLF_VALUE);
+ terminalDevice.setTerminalOutputFlag(TOF_VALUE);
+ terminalDevice.setTerminalInputFlag(TIF_VALUE);
+
+ readEntityStream = terminalDevice.getInputStream();
+ writeEntityStream = terminalDevice.getOutputStream();
+
+ serialWriteEntity = new SerialWriteEntity(this);
+ Thread.ofPlatform().start(serialWriteEntity);
+
+ serialReadEntity = new SerialReadEntity(this);
+ Thread.ofPlatform().start(serialReadEntity);
+
+ }
+
+ public String getMonitorName() {
+ return monitorName;
+ }
+
+ /**
+ * Tests whether the monitor is terminated by external means.
+ *
+ * @return true if terminated by the user, false otherwise.
+ */
+ public boolean isTerminate() {
+ return terminate;
+ }
+
+ /**
+ * Sets the termination flag to trigger termination on the next update.
+ */
+ public void setTerminate() {
+ this.terminate = true;
+ }
+
+ /**
+ * Gets the serial read input stream.
+ *
+ * @return the serial read input stream instance.
+ */
+ public InputStream getReadEntityStream() {
+ return readEntityStream;
+ }
+
+ /**
+ * Gets the terminal device controlling this monitor.
+ *
+ * @return the terminal device instance associated with this monitor.
+ */
+ public TerminalDevice getTerminalDevice() {
+ return terminalDevice;
+ }
+
+ /**
+ * Gets the Serial write output stream.
+ *
+ * @return an output stream representing this.
+ */
+ public OutputStream getWriteEntityStream() {
+ return writeEntityStream;
+ }
+
+ /**
+ * Gets the serial read entity used for reading data from the serial port using
+ * {@link SerialMonitor#readEntityStream}.
+ *
+ * @see SerialReadEntity
+ *
+ * @return the serial monitor read instance.
+ */
+ public SerialReadEntity getSerialReadEntity() {
+ return serialReadEntity;
+ }
+
+ /**
+ * Gets the serial write entity used for writing data to the serial port using
+ * {@link SerialMonitor#writeEntityStream}.
+ *
+ * @see SerialWriteEntity
+ *
+ * @return the serial monitor write instance.
+ */
+ public SerialWriteEntity getSerialWriteEntity() {
+ return serialWriteEntity;
+ }
+
+ /**
+ * Adds a new serial data listener to the list of the updatable listeners.
+ *
+ * @param serialDataListener the new serial data listener to add.
+ */
+ public void addSerialDataListener(final SerialDataListener serialDataListener) {
+ if (serialDataListeners.contains(serialDataListener)) {
+ return;
+ }
+ serialDataListeners.add(serialDataListener);
+ }
+
+ /**
+ * Removes a serial data listener instance from the list of the list of the updatable listeners.
+ *
+ * @param serialDataListener the serial data listener to remove.
+ */
+ public void removeSerialDataListener(final SerialDataListener serialDataListener) {
+ if (!serialDataListeners.contains(serialDataListener)) {
+ return;
+ }
+ serialDataListeners.remove(serialDataListener);
+ }
+
+ /**
+ * Sets the read entity status listener instance to listen for {@link SerialReadEntity} lifecycle.
+ *
+ * @param readThreadEntityStatus an instance to set.
+ */
+ public void setReadEntityListener(EntityStatus readThreadEntityStatus) {
+ this.serialReadEntityEntityStatus = readThreadEntityStatus;
+ }
+
+ /**
+ * Sets the write entity status listener instance to listen for {@link SerialWriteEntity} lifecycle.
+ *
+ * @param writeThreadEntityStatus an instance to set.
+ */
+ public void setWriteEntityStatus(EntityStatus writeThreadEntityStatus) {
+ this.serialWriteEntityEntityStatus = writeThreadEntityStatus;
+ }
+
+ /**
+ * Tests whether [CR/LF] check is enabled.
+ *
+ * @apiNote
+ * CR: Carriage return, defined by '\r'
+ * LF: Line Feed, defined by '\n'
+ *
+ * @return true if [CR/LF] is enabled, false otherwise.
+ */
+ public boolean isUsingReturnCarriage() {
+ return useReturnCarriage;
+ }
+
+ /**
+ * Triggers the [CR/LF] check state flag.
+ *
+ * @param useReturnCarriage true to enable [CR/LF] and return data frames
+ * at {@link SerialDataListener#onDataReceived(String)}, false to disable
+ * both the [CR/LF] check and disable {@link SerialDataListener#onDataReceived(String)}.
+ */
+ public void setUseReturnCarriage(boolean useReturnCarriage) {
+ this.useReturnCarriage = useReturnCarriage;
+ }
+
+ /**
+ * Gets the serial data listeners used for listening to data changes at the
+ * this monitor port.
+ *
+ * @return a list of serial data listeners for this monitor.
+ */
+ public ArrayList getSerialDataListeners() {
+ return serialDataListeners;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitorException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitorException.java
new file mode 100644
index 00000000..0cd87c9d
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/SerialMonitorException.java
@@ -0,0 +1,49 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.monitor;
+
+/**
+ * Raised whenever the user tries to access the serial monitor without opening the port.
+ *
+ * @author pavl_g.
+ */
+public class SerialMonitorException extends IllegalStateException {
+
+ /**
+ * Provides a default message for quick usages.
+ */
+ public static final String DEFAULT_MSG = "Cannot Access the monitor without opening the port !";
+
+ public SerialMonitorException(String msg) {
+ super(msg);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/package-info.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/package-info.java
new file mode 100644
index 00000000..8a3dab6f
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/monitor/package-info.java
@@ -0,0 +1,32 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.monitor;
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/package-info.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/package-info.java
new file mode 100644
index 00000000..3a006311
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/package-info.java
@@ -0,0 +1,39 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Provides a Serial UART Monitor API using Serial4j with 2 monitor entities, SerialReadEntity
+ * and SerialWriteEntity.
+ *
+ * @author pavl_g.
+ */
+package com.serial4j.core.serial;
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BadFileDescriptorException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BadFileDescriptorException.java
new file mode 100644
index 00000000..05f5a546
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BadFileDescriptorException.java
@@ -0,0 +1,47 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class BadFileDescriptorException extends SerialThrowable {
+
+ public BadFileDescriptorException(final String additionalText) {
+ super(Errno.EBADF.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EBADF;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BrokenPipeException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BrokenPipeException.java
new file mode 100644
index 00000000..53450a0e
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/BrokenPipeException.java
@@ -0,0 +1,49 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import java.io.IOException;
+import com.serial4j.core.errno.Errno;
+import com.serial4j.core.serial.throwable.SerialThrowable;
+
+public final class BrokenPipeException extends SerialThrowable {
+
+ public BrokenPipeException(final String additionalText) {
+ super(Errno.EPIPE.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EPIPE;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ErrnoNotFoundError.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ErrnoNotFoundError.java
new file mode 100644
index 00000000..69eff18b
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ErrnoNotFoundError.java
@@ -0,0 +1,51 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import java.lang.Error;
+
+/**
+ * Throwed when the API sends an undefined errno from the native side.
+ *
+ * @author pavl_g.
+ */
+public class ErrnoNotFoundError extends Error {
+
+ /**
+ * Constructs a new instance of this error.
+ *
+ * @param message a message to the java error object.
+ */
+ public ErrnoNotFoundError(final String message) {
+ super(message);
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileAlreadyOpenedException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileAlreadyOpenedException.java
new file mode 100644
index 00000000..c3e1fff0
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileAlreadyOpenedException.java
@@ -0,0 +1,47 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class FileAlreadyOpenedException extends SerialThrowable {
+
+ public FileAlreadyOpenedException(final String additionalText) {
+ super(Errno.EEXIST.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EEXIST;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileIsDirectoryException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileIsDirectoryException.java
new file mode 100644
index 00000000..6d05da05
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileIsDirectoryException.java
@@ -0,0 +1,47 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class FileIsDirectoryException extends SerialThrowable {
+
+ public FileIsDirectoryException(final String additionalText) {
+ super(Errno.EISDIR.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EISDIR;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTableOverflowException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTableOverflowException.java
new file mode 100644
index 00000000..6af3a2fd
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTableOverflowException.java
@@ -0,0 +1,47 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class FileTableOverflowException extends SerialThrowable {
+
+ public FileTableOverflowException(final String additionalText) {
+ super(Errno.ENFILE.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ENFILE;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTooLargeException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTooLargeException.java
new file mode 100644
index 00000000..4005a1a5
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/FileTooLargeException.java
@@ -0,0 +1,15 @@
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class FileTooLargeException extends SerialThrowable {
+
+ public FileTooLargeException(final String additionalText) {
+ super(Errno.EFBIG.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EFBIG;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InputOutputException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InputOutputException.java
new file mode 100644
index 00000000..abc58bf7
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InputOutputException.java
@@ -0,0 +1,15 @@
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class InputOutputException extends SerialThrowable {
+
+ public InputOutputException(final String additionalText) {
+ super(Errno.EIO.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EIO;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InterruptedSystemCallException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InterruptedSystemCallException.java
new file mode 100644
index 00000000..cfe3f705
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InterruptedSystemCallException.java
@@ -0,0 +1,15 @@
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class InterruptedSystemCallException extends SerialThrowable {
+
+ public InterruptedSystemCallException(final String additionalText) {
+ super(Errno.EINTR.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EINTR;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidArgumentException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidArgumentException.java
new file mode 100644
index 00000000..420787ea
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidArgumentException.java
@@ -0,0 +1,15 @@
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class InvalidArgumentException extends SerialThrowable {
+
+ public InvalidArgumentException(final String additionalText) {
+ super(Errno.EINVAL.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EINVAL;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidPortException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidPortException.java
new file mode 100644
index 00000000..a408450e
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/InvalidPortException.java
@@ -0,0 +1,49 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import java.lang.RuntimeException;
+import com.serial4j.core.serial.throwable.SerialThrowable;
+import com.serial4j.core.errno.Errno;
+
+public final class InvalidPortException extends SerialThrowable {
+
+ public InvalidPortException(final String portName) {
+ super(Errno.ERR_INVALID_PORT.getDescription() + "\n" + portName);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ERR_INVALID_PORT;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoAvailableTtyDevicesException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoAvailableTtyDevicesException.java
new file mode 100644
index 00000000..66c88334
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoAvailableTtyDevicesException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class NoAvailableTtyDevicesException extends SerialThrowable {
+
+ public NoAvailableTtyDevicesException(final String additionalText) {
+ super(Errno.ERR_NO_AVAILABLE_TTY_DEVICES.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ERR_NO_AVAILABLE_TTY_DEVICES;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSpaceLeftException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSpaceLeftException.java
new file mode 100644
index 00000000..ce5f53b2
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSpaceLeftException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public class NoSpaceLeftException extends SerialThrowable {
+
+ public NoSpaceLeftException(final String additionalText) {
+ super(Errno.ENOSPC.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ENOSPC;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchDeviceException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchDeviceException.java
new file mode 100644
index 00000000..444edf2b
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchDeviceException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class NoSuchDeviceException extends SerialThrowable {
+
+ public NoSuchDeviceException(final String additionalText) {
+ super(Errno.ENXIO.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ENXIO;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchFileException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchFileException.java
new file mode 100644
index 00000000..90760b28
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NoSuchFileException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class NoSuchFileException extends SerialThrowable {
+
+ public NoSuchFileException(final String additionalText) {
+ super(Errno.ENOENT.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ENOENT;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NotTtyDeviceException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NotTtyDeviceException.java
new file mode 100644
index 00000000..f0814a4d
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/NotTtyDeviceException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class NotTtyDeviceException extends SerialThrowable {
+
+ public NotTtyDeviceException(final String additionalText) {
+ super(Errno.ENOTTY.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.ENOTTY;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/PermissionDeniedException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/PermissionDeniedException.java
new file mode 100644
index 00000000..2052b8df
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/PermissionDeniedException.java
@@ -0,0 +1,61 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import java.io.IOException;
+import com.serial4j.core.errno.Errno;
+import com.serial4j.core.serial.throwable.SerialThrowable;
+
+/**
+ * Implements a permission exception for error code [EACCESS] or [13] as defined by .
+ * Possibly thrown from non-authorized permissions from a non-root user during an attempt to open
+ * a system resource.
+ *
+ * @author pavl_g.
+ */
+public class PermissionDeniedException extends SerialThrowable {
+
+ /**
+ * Instantiates a permission exception with an additionaltext and error code [13].
+ *
+ * @param additionalText additional text for the permission message.
+ */
+ public PermissionDeniedException(final String additionalText) {
+ super(Errno.EACCES.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EACCES;
+ }
+
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ReadOnlyFileSystemException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ReadOnlyFileSystemException.java
new file mode 100644
index 00000000..886f8f9d
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/ReadOnlyFileSystemException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class ReadOnlyFileSystemException extends SerialThrowable {
+
+ public ReadOnlyFileSystemException(final String additionalText) {
+ super(Errno.EROFS.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EROFS;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/SerialThrowable.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/SerialThrowable.java
new file mode 100644
index 00000000..7a2bedcc
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/SerialThrowable.java
@@ -0,0 +1,53 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+/**
+ * Defines an abstract entity for the serial throwable exceptions.
+ *
+ * @author pavl_g.
+ */
+public abstract class SerialThrowable extends RuntimeException {
+
+ public SerialThrowable(String message) {
+ super(message);
+ }
+
+ /**
+ * Gets the causing error code.
+ *
+ * @return the error code causing this exception.
+ */
+ abstract Errno getCausingErrno();
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TooManyOpenedFilesException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TooManyOpenedFilesException.java
new file mode 100644
index 00000000..bdb214cb
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TooManyOpenedFilesException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class TooManyOpenedFilesException extends SerialThrowable {
+
+ public TooManyOpenedFilesException(final String additionalText) {
+ super(Errno.EMFILE.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EMFILE;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TryAgainException.java b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TryAgainException.java
new file mode 100644
index 00000000..695f2623
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/serial/throwable/TryAgainException.java
@@ -0,0 +1,46 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.serial.throwable;
+
+import com.serial4j.core.errno.Errno;
+
+public final class TryAgainException extends SerialThrowable {
+
+ public TryAgainException(final String additionalText) {
+ super(Errno.EAGAIN.getDescription() + "\n" + additionalText);
+ }
+
+ @Override
+ public Errno getCausingErrno() {
+ return Errno.EAGAIN;
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/util/natives/NativeImageLoader.java b/HelloSerial4j/src/main/java/com/serial4j/core/util/natives/NativeImageLoader.java
new file mode 100644
index 00000000..6e7cc17f
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/util/natives/NativeImageLoader.java
@@ -0,0 +1,189 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The Arithmos Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.util.natives;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import com.serial4j.core.util.process.Semaphore;
+
+/**
+ * Helper utility for loading native images.
+ *
+ * @author pavl_g.
+ */
+public final class NativeImageLoader {
+
+ /**
+ * A state for a critical section.
+ */
+ public enum State {
+ TOGGLED,
+ }
+
+ /**
+ * Represents an image domain.
+ */
+ public enum NativeImage {
+ LINUX_x86_x64("native/Linux/linux-x86-x64/libserial4j.so"),
+ LINUX_x86_x86("native/Linux/linux-x86-x86/libserial4j.so"),
+ MAC_x86_x64("native/OSX/mac-x86-x64/libserial4j.dylb"),
+ WIN_x86_x64("native/Windows/win-x86-x64/libserial4j.dll");
+
+ private final String image;
+
+ NativeImage(final String image) {
+ this.image = image;
+ }
+
+ public String getImage() {
+ return image;
+ }
+ }
+
+ /**
+ * Represents an operating system domain.
+ */
+ private enum OS {
+ NAME(System.getProperty("os.name")),
+ ARCH(System.getProperty("os.arch"));
+
+ public static final String Linux = "Linux";
+ public static final String Windows = "Windows";
+ public static final String Mac = "Mac";
+ public static final String Android = "Android";
+
+ private final String data;
+
+ OS(final String data) {
+ this.data = data;
+ }
+ public String getData() {
+ return data;
+ }
+
+ /** WIP */
+
+ public static boolean is_x86_x64(final String arch) {
+ return arch.equals("amd64");
+ }
+ public static boolean is_x86_x86(final String arch) {
+ return arch.equals("amd32");
+ }
+ public static boolean is_arrm32(final String arch) {
+ return arch.equals("armhf");
+ }
+ }
+
+ protected static final Semaphore.Mutex MUTEX = new Semaphore.Mutex();
+ protected static final Semaphore SEMAPHORE = Semaphore.build(MUTEX);
+
+ private static boolean isLoaded = false;
+
+ private NativeImageLoader() {
+ }
+
+ public static void loadLibrary() {
+ if (OS.NAME.getData().equals(OS.Linux)) {
+ loadLinux();
+ } else if (OS.NAME.getData().equals(OS.Windows)) {
+ /** WIP */
+ } else if (OS.NAME.getData().equals(OS.Mac)) {
+ /** WIP */
+ } else if (OS.NAME.getData().equals(OS.Android)) {
+ loadAndroid();
+ }
+ }
+
+ private static void loadLinux() {
+ if (OS.is_x86_x64(OS.ARCH.getData())) {
+ extractImage(NativeImage.LINUX_x86_x64);
+ }
+ }
+
+ private static void loadWindows() {
+ /** WIP */
+ }
+
+ private static void loadMac() {
+ /** WIP */
+ }
+
+ private static void loadAndroid() {
+ System.loadLibrary("Serial4j");
+ }
+
+ /**
+ * Extracts an appropriate system-based native image from sources.
+ *
+ * @param image the image to extract to the user directory.
+ */
+ private static void extractImage(final NativeImage image) {
+
+ // protect a critical section
+ initMutexWithLockData();
+
+ SEMAPHORE.lock(NativeImageLoader.class);
+
+ if (isLoaded) {
+ SEMAPHORE.unlock(NativeImageLoader.class);
+ return;
+ }
+
+ // extract the shipped native files
+ final String workingDirectory = System.getProperty("user.dir");
+ try {
+ final InputStream nativeImageIS = NativeImageLoader.class.getClassLoader().getResourceAsStream(image.getImage());
+ final byte[] buffer = new byte[nativeImageIS.available()];
+ final FileOutputStream fos = new FileOutputStream(workingDirectory + "/libserial4j.so");
+ int numberOfReadBytes = 0;
+ while ((numberOfReadBytes = nativeImageIS.read(buffer)) != -1) {
+ /* use the numberOfReadBytes as the buffer length to write valid data */
+ fos.write(buffer, 0, numberOfReadBytes);
+ }
+ nativeImageIS.close();
+ fos.close();
+ System.load(workingDirectory + "/libserial4j.so");
+ } catch(final Exception exception) {
+ exception.printStackTrace();
+ }
+
+ isLoaded = true;
+
+ SEMAPHORE.unlock(NativeImageLoader.class);
+
+ }
+
+ private static void initMutexWithLockData() {
+ MUTEX.setLockData(NativeImageLoader.State.TOGGLED);
+ MUTEX.setMonitorObject(NativeImageLoader.class);
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/core/util/process/Semaphore.java b/HelloSerial4j/src/main/java/com/serial4j/core/util/process/Semaphore.java
new file mode 100644
index 00000000..3338a30c
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/core/util/process/Semaphore.java
@@ -0,0 +1,131 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The Arithmos Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.core.util.process;
+
+import java.util.logging.Logger;
+
+/**
+ * A thread synchronizer utility using mutex data states.
+ *
+ * @see Semaphore.Mutex
+ * @author pavl_g.
+ */
+public final class Semaphore {
+ private final Mutex mutex;
+ private static final Logger logger = Logger.getLogger(Semaphore.class.getName());
+
+ public static final class Mutex {
+ private Object lockData;
+ private Object monitorObject;
+ private Object unlockData;
+
+ public Mutex(final O monitorObject, final LD lockData, final ULD unlockData) {
+ this.monitorObject = monitorObject;
+ this.lockData = lockData;
+ this.unlockData = unlockData;
+ }
+
+ public Mutex() {
+ this(new Object(), new Object(), new Object());
+ }
+
+ public void setLockData(Object lockData) {
+ this.lockData = lockData;
+ }
+
+ public void setMonitorObject(Object monitorObject) {
+ this.monitorObject = monitorObject;
+ }
+
+ protected void setUnlockData(Object unlockData) {
+ this.unlockData = unlockData;
+ }
+
+ public Object getLockData() {
+ return lockData;
+ }
+
+ public Object getMonitorObject() {
+ return monitorObject;
+ }
+
+ public Object getUnlockData() {
+ return unlockData;
+ }
+
+ /**
+ * Creates a 'no job' job to trick the java loop.
+ * (a java loop must have something inside to act upon).
+ *
+ * @return a null job.
+ */
+ protected final Void NO_JOB() {
+ return null;
+ }
+ }
+
+ private Semaphore(Mutex mutex) {
+ this.mutex = mutex;
+ }
+
+ public static Semaphore build(Mutex mutex) {
+ logger.fine("Semaphore initialized with monitor " + mutex.getMonitorObject() + " and data object " + mutex.getLockData());
+ return new Semaphore(mutex);
+ }
+
+ public void lock(final MO monitorObject) {
+ // order for a lock
+ this.mutex.setMonitorObject(monitorObject);
+ // format the unlock data for a new lock dispatcher
+ this.mutex.setUnlockData(new Object());
+ logger.fine("Lock obtained with monitor " + monitorObject);
+ }
+
+ public void waitForUnlock() {
+ while (mutex.getLockData() != mutex.getUnlockData()) {
+ final Void NO_JOB = mutex.NO_JOB();
+ }
+ }
+
+ public void unlock(final O locker) {
+ if (locker != mutex.getMonitorObject()) {
+ throw new IllegalMonitorStateException("The current thread doesn't own this object !");
+ }
+ // release the lock
+ mutex.setUnlockData(mutex.getLockData());
+ logger.fine(locker + " Unlocked");
+ }
+
+ public Mutex getMutex() {
+ return mutex;
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/example/Launcher.java b/HelloSerial4j/src/main/java/com/serial4j/example/Launcher.java
new file mode 100644
index 00000000..f1f14b4a
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/example/Launcher.java
@@ -0,0 +1,51 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.example;
+
+import com.serial4j.example.serial4j.HelloSerial4jIO;
+import com.serial4j.example.serial4j.HelloNativeSerial4J;
+import com.serial4j.example.monitor.HelloSerialMonitor;
+
+/**
+ * Starts the applications test cases.
+ *
+ * @author pavl_g.
+ */
+public final class Launcher {
+
+ public static void main(String args[]) throws InterruptedException {
+ /* starts the native fctnl io example */
+ // Thread.ofVirtual().start(new HelloNativeSerial4J());
+ Thread.ofPlatform().start(new HelloSerialMonitor());
+ while (true);
+ }
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/java/com/serial4j/example/monitor/HelloSerialMonitor.java b/HelloSerial4j/src/main/java/com/serial4j/example/monitor/HelloSerialMonitor.java
new file mode 100644
index 00000000..6fbb91c2
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/example/monitor/HelloSerialMonitor.java
@@ -0,0 +1,123 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.example.monitor;
+
+import com.serial4j.core.serial.BaudRate;
+import com.serial4j.core.serial.entity.EntityStatus;
+import com.serial4j.core.serial.entity.impl.WritableCapsule;
+import com.serial4j.core.serial.entity.impl.SerialWriteEntity;
+import com.serial4j.core.serial.monitor.SerialDataListener;
+import com.serial4j.core.serial.monitor.SerialMonitor;
+
+/**
+ * Represents an example for UART using jSerialComm.
+ *
+ * @author pavl_g.
+ */
+public class HelloSerialMonitor implements SerialDataListener, EntityStatus, Runnable {
+
+ private static boolean isDataSent;
+
+ @Override
+ public void run() {
+ System.out.println(Thread.currentThread());
+ System.out.println("---------------Welcome to Serial4j Monitor Testcase---------------");
+ try {
+ final SerialMonitor serialMonitor = new SerialMonitor("Monitor A");
+ serialMonitor.startDataMonitoring("/dev/ttyUSB0", BaudRate.B57600, null);
+ serialMonitor.setWriteEntityStatus(this);
+ serialMonitor.addSerialDataListener(this);
+
+ // /* write data to UART with return-carriage/newline */
+ // delay(2000);
+ // writeInUARTCapsule(serialMonitor, "0\n\r");
+
+ /* terminate after 20 seconds */
+ delay(20000);
+ serialMonitor.setTerminate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void writeInUARTCapsule(final SerialMonitor serialMonitor, final String data) {
+ final WritableCapsule writableCapsule = new WritableCapsule();
+ writableCapsule.write(data);
+ serialMonitor.getSerialWriteEntity().addWritableCapsule(writableCapsule);
+ }
+
+ private void delay(final long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onSerialEntityInitialized(SerialWriteEntity serialMonitorEntity) {
+
+ }
+
+ @Override
+ public void onSerialEntityTerminated(SerialWriteEntity serialMonitorEntity) {
+ System.err.println("Serial4j: Terminated");
+ }
+
+ @Override
+ public void onUpdate(SerialWriteEntity serialMonitorEntity) {
+ if (isDataSent) {
+ return;
+ }
+ /* send data after 5 seconds */
+ delay(5000);
+ /* send data in a UART capsule on the serial write entity thread */
+ writeInUARTCapsule(serialMonitorEntity.getSerialMonitor(), "0\n");
+ isDataSent = true;
+ }
+
+ @Override
+ public void onDataReceived(int data) {
+
+ }
+
+ @Override
+ public void onDataTransmitted(int data) {
+
+ }
+
+ @Override
+ public void onDataReceived(String data) {
+ System.out.println(Thread.currentThread());
+ System.out.println(data);
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloNativeSerial4J.java b/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloNativeSerial4J.java
new file mode 100644
index 00000000..08945dd8
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloNativeSerial4J.java
@@ -0,0 +1,174 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.example.serial4j;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.io.FileNotFoundException;
+import java.util.logging.Logger;
+import com.serial4j.core.serial.control.TerminalControlFlag;
+import com.serial4j.core.serial.control.TerminalLocalFlag;
+import com.serial4j.core.serial.control.TerminalOutputFlag;
+import com.serial4j.core.serial.control.TerminalInputFlag;
+import com.serial4j.core.serial.ReadConfiguration;
+import com.serial4j.core.serial.Permissions;
+import com.serial4j.core.serial.BaudRate;
+import com.serial4j.core.serial.SerialPort;
+import com.serial4j.core.serial.TerminalDevice;
+import com.serial4j.core.serial.throwable.PermissionDeniedException;
+import com.serial4j.core.serial.throwable.BrokenPipeException;
+import com.serial4j.core.serial.throwable.NoSuchDeviceException;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+import com.serial4j.core.serial.throwable.OperationFailedException;
+
+/**
+ * An example for Serial4j showing Native terminal control and
+ * native file io on a serial port using a java binding to and read (...) and write (...).
+ *
+ * @author pavl_g.
+ */
+public final class HelloNativeSerial4J implements Runnable {
+
+ /**
+ * Provides a java binding to a native terminal device.
+ */
+ protected final TerminalDevice ttyDevice = new TerminalDevice();
+
+ protected static final Logger EXAMPLE_LOGGER = Logger.getLogger(HelloNativeSerial4J.class.getName());
+
+ @Override
+ public void run() {
+ System.out.println(Thread.currentThread());
+ try {
+ System.out.println("Started native io example: ");
+ /* set port permissions */
+ final Permissions permissions = Permissions.O_RDWR.append(Permissions.O_NOCTTY)
+ .append(Permissions.O_NONBLOCK);
+ ttyDevice.setPermissions(permissions);
+ /* define terminal flags */
+ final TerminalControlFlag TCF_VALUE = (TerminalControlFlag) TerminalControlFlag.CLOCAL
+ .append(TerminalControlFlag.CS8, TerminalControlFlag.CREAD);
+ final TerminalLocalFlag TLF_VALUE = (TerminalLocalFlag) TerminalLocalFlag.EMPTY_INSTANCE
+ .disable(TerminalLocalFlag.ECHO, TerminalLocalFlag.ECHOK,
+ TerminalLocalFlag.ECHOE, TerminalLocalFlag.ECHOKE,
+ TerminalLocalFlag.ECHONL, TerminalLocalFlag.ECHOPRT,
+ TerminalLocalFlag.ECHOCTL, TerminalLocalFlag.ISIG,
+ TerminalLocalFlag.IEXTEN, TerminalLocalFlag.ICANON);
+ final TerminalOutputFlag TOF_VALUE = (TerminalOutputFlag) TerminalOutputFlag.EMPTY_INSTANCE
+ .disable(TerminalOutputFlag.OPOST, TerminalOutputFlag.ONLCR);
+ final TerminalInputFlag TIF_VALUE = (TerminalInputFlag) TerminalInputFlag.EMPTY_INSTANCE.disableAll();
+ /* open the serial port using the path or the name */
+ ttyDevice.openPort(new SerialPort("/dev/ttyUSB0"));
+ /* initialize the terminal IO with the default terminal flags */
+ ttyDevice.initTermios();
+ /* print the initial terminal control flags as long value */
+ System.out.println(ttyDevice.getTerminalControlFlag().getValue());
+ /* set and update the new terminal flags */
+ ttyDevice.setTerminalControlFlag(TCF_VALUE);
+ ttyDevice.setTerminalLocalFlag(TLF_VALUE);
+ ttyDevice.setTerminalOutputFlag(TOF_VALUE);
+ ttyDevice.setTerminalInputFlag(TIF_VALUE);
+ /* print the new terminal control flag */
+ System.out.println(ttyDevice.getTerminalControlFlag().getValue());
+ /* set the baud rate (bits/second) */
+ ttyDevice.setBaudRate(BaudRate.B57600);
+ /* set the reading mode config to interbyte timeout of delay 510 bytes and delay of 5ms between each charachter */
+ ttyDevice.setReadConfigurationMode(ReadConfiguration.READ_WITH_INTERBYTE_TIMEOUT, 0, 255);
+
+ /* print the port file descriptor */
+ if (ttyDevice.getSerialPort().getFd() > 0) {
+ System.out.println("Port Opened with " + ttyDevice.getSerialPort().getFd());
+ }
+ System.out.println(Arrays.toString(ttyDevice.getReadConfigurationMode().getMode()));
+ System.out.println(Arrays.toString(ttyDevice.getSerialPorts()) + " " + ttyDevice.getSerialPorts().length);
+ // /* start the R/W threads */
+ startReadThread(ttyDevice, 0);
+ startWriteThread(ttyDevice, 20000);
+ } catch(FileNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Uses the [extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur] provided by base posix api
+ * to read from the pre-initialized port in a new thread.
+ *
+ * @param ttyDevice the terminal device object to read the data from.
+ * @param millis a delay before the reading operation starts in ms.
+ */
+ private void startReadThread(final TerminalDevice ttyDevice, final long millis) {
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(millis);
+ long read;
+ while(true) {
+ /* read data and get the buffer */
+ if ((read = ttyDevice.readBuffer()) > 0) {
+ System.out.println(read);
+ System.out.println(ttyDevice.getReadBuffer());
+ // System.exit(0);
+ }
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ /**
+ * Uses the [extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur] provided by base posix api
+ * to write to the pre-initialized port in a new thread.
+ *
+ * @param ttyDevice the terminal device object to write the data to.
+ * @param millis a delay before the writing operation starts in ms.
+ */
+ private void startWriteThread(final TerminalDevice ttyDevice, final long millis) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ /* write a buffer (array of chars) and close the port */
+ Thread.sleep(millis);
+ ttyDevice.writeData(new int[] {'A', 'B'});
+ Thread.sleep(millis / 2);
+ ttyDevice.closePort();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+}
diff --git a/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloSerial4jIO.java b/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloSerial4jIO.java
new file mode 100644
index 00000000..2d463c17
--- /dev/null
+++ b/HelloSerial4j/src/main/java/com/serial4j/example/serial4j/HelloSerial4jIO.java
@@ -0,0 +1,138 @@
+/*
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.serial4j.example.serial4j;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.io.FileNotFoundException;
+import com.serial4j.core.serial.BaudRate;
+import com.serial4j.core.serial.SerialPort;
+import com.serial4j.core.serial.TerminalDevice;
+import com.serial4j.core.serial.ReadConfiguration;
+import com.serial4j.core.serial.throwable.PermissionDeniedException;
+import com.serial4j.core.serial.throwable.BrokenPipeException;
+import com.serial4j.core.serial.throwable.NoSuchDeviceException;
+import com.serial4j.core.serial.throwable.InvalidPortException;
+import com.serial4j.core.serial.throwable.OperationFailedException;
+import com.serial4j.core.serial.Permissions;
+
+/**
+ * An example showing serial and terminal io using java.io API.
+ *
+ * @author pavl_g.
+ */
+public final class HelloSerial4jIO implements Runnable {
+
+ /**
+ * Provides a java binding to the native terminal device.
+ */
+ protected final TerminalDevice ttyDevice = new TerminalDevice();
+
+ @Override
+ public void run() {
+ try {
+ System.out.println("Started java io example: ");
+ /* disable native logger */
+ /* enable java logger */
+ ttyDevice.setSerial4jLoggingEnabled(true);
+ ttyDevice.openPort(new SerialPort(ttyDevice.getSerialPorts()[0]));
+ if (ttyDevice.getSerialPort().getFd() > 0) {
+ System.out.println("Port Opened with " + ttyDevice.getSerialPort().getFd());
+ } else {
+ System.err.println("Cannot open serial port" + " " + ttyDevice.getSerialPort().getFd());
+ }
+ /* initialize terminal io base POSIX library with the default terminal flags */
+ ttyDevice.initTermios();
+ /* set and apply the baud rate to determine transmission speed */
+ ttyDevice.setBaudRate(BaudRate.B57600);
+ System.out.println("Available serial ports: " + Arrays.toString(ttyDevice.getSerialPorts()) + " " + ttyDevice.getSerialPorts().length);
+ /* start R/W threads */
+ startReadThread(ttyDevice, 0);
+ startWriteThread(ttyDevice, 1000);
+ } catch(NoSuchDeviceException |
+ PermissionDeniedException |
+ BrokenPipeException |
+ InvalidPortException |
+ OperationFailedException |
+ FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Uses the {@link java.io.FileOutputStream} to write to the pre-initialized port in a new thread.
+ *
+ * @param ttyDevice the terminal device object to get the {@link FileOutputStream} from.
+ * @param millis a delay before the writing operation starts in ms.
+ */
+ private static void startWriteThread(final TerminalDevice ttyDevice, final long millis) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(millis);
+ /* uses the java io to write to the serial port */
+ ttyDevice.getOutputStream().write('A');
+ ttyDevice.getOutputStream().write('D');
+ ttyDevice.closePort();
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+
+ /**
+ * Uses the {@link java.io.FileInputStream} to read from the pre-initialized port in a new thread.
+ *
+ * @param ttyDevice the terminal device object to get the {@link FileInputStream} from.
+ * @param millis a delay before the writing operation starts in ms.
+ */
+ private static void startReadThread(final TerminalDevice ttyDevice, final long millis) {
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(millis);
+ while(true) {
+ /* check for the number of the available charachters to read */
+ if (ttyDevice.getInputStream().available() > 0) {
+ System.out.print((char) ttyDevice.getInputStream().read());
+ }
+ }
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+ }
+}
diff --git a/HelloSerial4j/src/main/native/include/BufferUtils.h b/HelloSerial4j/src/main/native/include/BufferUtils.h
new file mode 100644
index 00000000..06b3895b
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/BufferUtils.h
@@ -0,0 +1,124 @@
+/**
+ * @file BufferUtils.util
+ * @author pavl_g.
+ * @brief Represents utility functions for buffers.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef BUFFER_UTILS
+#define BUFFER_UTILS
+
+#include
+#include
+#include
+
+namespace BufferUtils {
+
+ /**
+ * Nullifies a single buffer cell at the index.
+ *
+ * @param buffer the buffer to nullify its cell.
+ * @param index the index of the buffer cell to nullify.
+ */
+ static inline void nullifyBuffer(void** buffer, int index) {
+ buffer[index] = NULL;
+ }
+
+ /**
+ * Frees the memory utilized by the individual buffer cells on a [buffer] with [count] number of cells.
+ *
+ * @param buffer the buffer to free its cells.
+ * @param count the number of cells to free, starting from index zero.
+ */
+ static inline void freeBufferCells(void** buffer, int* count) {
+ for (int i = 0; i < *count; i++) {
+ BufferUtils::nullifyBuffer(buffer, i);
+ free(buffer[i]);
+ }
+ }
+
+ /**
+ * @brief Deletes a typified buffer and frees its memory.
+ *
+ * @param buffer the buffer to delete.
+ */
+ static inline void deleteBuffer(void* buffer) {
+ free(buffer);
+ BufferUtils::nullifyBuffer(&buffer, 0);
+ }
+
+ /**
+ * @brief Deeply copies the data of the [src] buffer into a new
+ * buffer and returns it.
+ *
+ * @param src the source buffer to get the data from.
+ * @param count the count length of the buffer.
+ * @return void** a new buffer with the same data as the source.
+ */
+ static inline void** copy(void** src, int* count) {
+ void** copy = (void**) calloc(1, sizeof(void**));
+ for (int i = 0; i < *count; i++) {
+ /* add new memory on the next array block */
+ copy[i] = (void*) calloc(1, sizeof(void*));
+ copy[i] = src[i];
+ }
+ return copy;
+ }
+
+ /**
+ * @brief Re-validates the buffer from [NULL] pointers.
+ *
+ * @param buffer the buffer to re-validate.
+ * @param count the pointers count.
+ */
+ static inline void reValidateBuffer(void** buffer, int* count, int* isProcessed) {
+ /* get a temp copy from flagged buffer */
+ void** temp = BufferUtils::copy(buffer, count);
+ /* free the buffer cells to prepare the buffer to be reinitialized */
+ BufferUtils::freeBufferCells(buffer, count);
+ /* re-init the buffer, removing the null pointers */
+ for (int i = 0, j = 0; i < *count; i++) {
+ if (temp[i] == NULL) {
+ printf("%s\n", "zero");
+ continue;
+ }
+ buffer[j] = (void*) calloc(1, sizeof(void*));
+ buffer[j] = temp[i];
+ j++;
+ }
+ *isProcessed = 1;
+ /* free the temp buffer */
+ BufferUtils::freeBufferCells(temp, count);
+ }
+}
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/DynamicBuffer.h b/HelloSerial4j/src/main/native/include/DynamicBuffer.h
new file mode 100644
index 00000000..8b86e85c
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/DynamicBuffer.h
@@ -0,0 +1,156 @@
+/**
+ * @file DynamicBuffer.h
+ * @author pavl_g.
+ * @brief Represents a cross platform dynamic buffer wrapper.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef DY_BUFFER
+
+#define DY_BUFFER 1
+
+#include
+#include
+#include
+
+struct DynamicBuffer {
+
+ int count = 0;
+ int isProcessed = 0;
+
+ /**
+ * Declares and initializes a pointer that points to
+ * other void* buffers starting from index zero.
+ *
+ * @note The pointer is of single size of a type.
+ * @note The pointer points to only and only one buffer at a time.
+ * @note New buffers can be added to this pointer by dereferencing it and adding one to the memory address to move
+ * it to a new cell block.
+ * e.g:
+ * 1) First way of adding a new buffer to this pointer using the deep copy:
+ * buffer[index] = (void*) calloc(1, sizeof(void*));
+ * buffer[index] = item;
+ *
+ * 2) Second way of adding a new buffer to this pointer (the one used here):
+ * *(buffer += count) = (void*) calloc(1, sizeof(void*));
+ * *buffer = item;
+ * buffer -= count;
+ *
+ * 3) The superficial copy example:
+ * buffer[index] = item;
+ */
+ void** buffer = (void**) calloc(1, sizeof(void**));;
+
+ static inline struct DynamicBuffer* createNewInstance() {
+ return (struct DynamicBuffer*) calloc(1, sizeof(struct DynamicBuffer));
+ }
+
+ /**
+ * Retrieves the pointer to this dynamic buffer.
+ *
+ * @return a pointer to this array of buffers.
+ */
+ void** getBuffer() {
+ return buffer;
+ }
+
+ /**
+ * Retrieves this structure size.
+ *
+ * @return an integer representing this struct in bytes.
+ */
+ size_t getBufferSize() {
+ return sizeof(struct DynamicBuffer);
+ }
+
+ /**
+ * Resets the pointer value back to zero.
+ */
+ void resetDataPointer() {
+ this->count = 0;
+ }
+
+ /**
+ * Gets the memory address to the integer of the items count.
+ *
+ * @return a pointer referring to the memory address of the integer that represents the item counts.
+ */
+ int* getItemsCount();
+
+ /**
+ * Adds a new buffer to this pointer in a new index.
+ *
+ * @param item a void* buffer to add.
+ */
+ void add(void* item);
+
+ /**
+ * Adds a new buffer on a particular location in this pointer replacing an old one if exists.
+ *
+ * @param index the index where the new buffer will be located in this pointer.
+ * @param item the buffer to add.
+ */
+ void add(int index, void* item);
+
+ /**
+ * Frees a buffer from the memory at a particular index.
+ * @warning this method call is expensive as it removes and revalidates the whole buffer from NULL pointers.
+ *
+ * @param index the index of the buffer to remove.
+ */
+ void removeAt(int index);
+
+ /**
+ * Frees all the buffers of this pointer from the memory.
+ */
+ void removeAll();
+
+ /**
+ * Retrieves a buffer index.
+ *
+ * @param item the buffer to get its index.
+ * @return the buffer index in an integer format.
+ */
+ int getItemIndex(void* item);
+
+ /**
+ * Retrieves a buffer from this pointer using its index.
+ *
+ * @param index the index where the buffer is located in this pointer.
+ * @return the buffer corresponding to this index.
+ */
+ void* getItem(int index);
+};
+
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/ErrnoUtils.h b/HelloSerial4j/src/main/native/include/ErrnoUtils.h
new file mode 100644
index 00000000..7e821372
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/ErrnoUtils.h
@@ -0,0 +1,53 @@
+/**
+ * @file ErrnoUtils.util
+ * @author pavl_g.
+ * @brief Represents native user and machine errnos.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef ERRNO_UTILS
+#define ERRNO_UTILS
+
+#include
+
+#define ERR_INVALID_PORT (-2)
+#define ERR_INVALID_DIR (-3)
+#define ERR_NO_RESULT (0)
+#define LOGGER_DISABLED (-5)
+#define ERR_OPERATION_FAILED (-1)
+#define ERR_NO_AVAILABLE_TTY_DEVICES (-4)
+
+#define OPERATION_SUCCEEDED (1)
+
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/JniUtils.h b/HelloSerial4j/src/main/native/include/JniUtils.h
new file mode 100644
index 00000000..65647a46
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/JniUtils.h
@@ -0,0 +1,327 @@
+/**
+ * @file JniUtils.util
+ * @author pavl_g.
+ * @brief Java Native Interface Utility methods for jni java 8 and invocation api.
+ * @version 0.1
+ * @date 2022-08-28
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef JNI_UTILS
+#define JNI_UTILS
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define CONSTRUCTOR ((const char*) "")
+#define STATIC_INIT ((const char*) "")
+
+#define NON_PARAMTERIZED_VOID_SIG ((const char*) "()V")
+#define NON_PARAMETERIZED_INT_SIG ((const char*) "()I")
+#define NON_PARAMETERIZED_STRING_SIG ((const char*) "()[Ljava/lang/String;")
+#define NON_PARAMETERIZED_LONG_SIG ((const char*) "()J")
+
+#define java_lang_String ((const char*) "java/lang/String")
+#define java_io_IOException ((const char*) "java/io/IOException")
+#define java_io_InputStream ((const char*) "java/io/InputStream")
+#define java_io_OutputStream ((const char*) "java/io/OutputStream")
+#define java_io_FileInputStream ((const char*) "java/io/FileIntputStream")
+#define java_io_FileOutputStream ((const char*) "java/io/FileOutputStream")
+
+namespace JniUtils {
+
+ static JNIEnv* env;
+ static JavaVM* jvm;
+ static jint version;
+ static struct JavaVMAttachArgs* jvmArgs;
+
+ /**
+ * @brief Sets the Jni Env pointer for jni functions.
+ *
+ * @param env the environment pointer to use.
+ */
+ static inline int setupJavaEnvironment(JNIEnv* env, jint version) {
+ if (env == NULL) {
+ return ERR_OPERATION_FAILED;
+ }
+ env->GetJavaVM(&JniUtils::jvm);
+ JniUtils::version = version;
+ return OPERATION_SUCCEEDED;
+ }
+
+ static inline JavaVM* getJavaVM() {
+ return JniUtils::jvm;
+ }
+
+ /**
+ * @brief Gets the Jni Env pointer from the jvm with multithreading support.
+ *
+ * @return JNIEnv* the namespace env pointer.
+ */
+ static inline JNIEnv** getJniEnv() {
+ JniUtils::jvm->GetEnv((void**) &JniUtils::env, version);
+ return &JniUtils::env;
+ }
+
+ static inline struct JavaVMAttachArgs* getJVMAttachArgs(jint jreVersion, char* threadName, jobject threadGroupObj) {
+ jvmArgs->version = jreVersion;
+ jvmArgs->name = threadName;
+ jvmArgs->group = threadGroupObj;
+ return jvmArgs;
+ }
+
+ static inline jint attachNativeThread(char* threadName, jobject threadGroupObj) {
+ void** jniEnvPointer = (void**) JniUtils::getJniEnv();
+ struct JavaVMAttachArgs* jvmArgs = getJVMAttachArgs(JniUtils::version, threadName, threadGroupObj);
+ return JniUtils::getJavaVM()->AttachCurrentThread(jniEnvPointer, jvmArgs);
+ }
+
+ /**
+ * @brief Retrieves a java class from a name, the name is referred to by the
+ * package/class, example: {"com/java/io/IOException"}.
+ *
+ * @param clazzName the class name using the format {package/class}.
+ * @return jclass the reflected java class.
+ */
+ static inline jclass getClassFromString(const char* clazzName) {
+ return (*JniUtils::getJniEnv())->FindClass(clazzName);
+ }
+
+ /**
+ * @brief Retrieves a java class method using the [methodName] for the method name
+ * and the [sig] for the method signature.
+ *
+ * @param clazzName the class name in the format {"package/class"}.
+ * @param methodName the method name, use `` for constructors.
+ * @param sig the method signature, eg: ()V for non-parameterized void method.
+ * @return jmethodID a new method id for the requested method.
+ */
+ static inline jmethodID getClassMethod(const char* clazzName, const char* methodName, const char* sig) {
+ return (*JniUtils::getJniEnv())->GetMethodID(getClassFromString(clazzName), methodName, sig);
+ }
+
+ /**
+ * @brief Retrieves the java class constructor.
+ *
+ * @version version 0 from getClassConstructor for parameteized constructors using constructor
+ * signature.
+ * @param clazzName the java class name in the format {"package/class"}.
+ * @param sig the constructor signature, eg: ()V for non-parameterized void type.
+ * @return jmethodID an id referring to the class constructor.
+ */
+ static inline jmethodID getClassConstructor0(const char* clazzName, const char* sig) {
+ return JniUtils::getClassMethod(clazzName, CONSTRUCTOR, sig);
+ }
+
+ /**
+ * @brief Retrieves the java class non-parameterized constructor with signature
+ * [NON_PARAMTERIZED_VOID_SIG].
+ *
+ * @param clazzName the java class name.
+ * @return jmethodID an id referring to the class non-parameterized constructor.
+ */
+ static inline jmethodID getClassConstructor1(const char* clazzName) {
+ return JniUtils::getClassConstructor0(clazzName, NON_PARAMTERIZED_VOID_SIG);
+ }
+
+ /**
+ * @brief Calls a parameterized method [methodName] from class [clazzName].
+ *
+ * @param clazzName the class name where the method is located, eg: {"java/io/IOException"}.
+ * @param methodName the method name to call.
+ * @param sig the signature of the method, eg: ()V for non-paramterized void methods.
+ * @param args an array for the method parameters of type [jvalue] referring to one of the JNI
+ * data types [jint, jbyte, jlong, jshort, jchar, jobject...etc].
+ */
+ static inline void callParameterizedMethod(const char* clazzName, const char* methodName, const char* sig, jvalue* args) {
+ jclass clazz = JniUtils::getClassFromString(clazzName);
+ jmethodID mid = JniUtils::getClassMethod(clazzName, methodName, sig);
+ if (args == NULL) {
+ (*JniUtils::getJniEnv())->CallVoidMethod(clazz, mid);
+ } else {
+ (*JniUtils::getJniEnv())->CallVoidMethod(clazz, mid, args);
+ }
+ }
+
+ /**
+ * @brief Calls a non-parameterized method [methodName] with signature [sig].
+ *
+ * @param clazzName the class name where the method is located, eg: {"java/lang/String"}.
+ * @param methodName the method name to call.
+ * @param sig the signature of the method, eg: ()V, ()I, ()J.
+ */
+ static inline void callNonParameterizedMethod(const char* clazzName, const char* methodName, const char* sig) {
+ JniUtils::callParameterizedMethod(clazzName, methodName, sig, NULL);
+ }
+
+ /**
+ * @brief Calls a class parameterized constructor ( method) with
+ * signature and jvalue (holds only one variable of one JNI data type at a time) parameters.
+ *
+ * @param clazzName
+ * @param sig
+ * @param args
+ */
+ static inline void callParameterizedConstructor(const char* clazzName, const char* sig, jvalue* args) {
+ JniUtils::callParameterizedMethod(clazzName, CONSTRUCTOR, sig, args);
+ }
+
+ static inline void callNonParameterizedConstructor(const char* clazzName) {
+ JniUtils::callParameterizedConstructor(clazzName, NON_PARAMTERIZED_VOID_SIG, NULL);
+ }
+
+ static inline jobject getObjectFromClass0(const char* clazzName) {
+ return (*JniUtils::getJniEnv())->AllocObject(JniUtils::getClassFromString(clazzName));
+ }
+
+ static inline jobject getObjectFromClass1(const char* clazzName, jmethodID constructor) {
+ return (*JniUtils::getJniEnv())->NewObject(JniUtils::getClassFromString(clazzName), constructor);
+ }
+
+ static inline jobject getObjectFromClass2(const char* clazzName) {
+ return JniUtils::getObjectFromClass1(clazzName, JniUtils::getClassConstructor1(clazzName));
+ }
+
+ static inline jclass getObjectClass(jobject* object) {
+ return (*JniUtils::getJniEnv())->GetObjectClass(*object);
+ }
+
+ static inline jfieldID getFieldIDFromObject(jobject* object, const char* fieldName, const char* fieldSig) {
+ return (*JniUtils::getJniEnv())->GetFieldID(getObjectClass(object), fieldName, fieldSig);
+ }
+
+ static inline jobject getObjectFieldFromClass(jobject* object, const char* fieldName, const char* fieldSig) {
+ jfieldID fieldId = getFieldIDFromObject(object, fieldName, fieldSig);
+ return (*JniUtils::getJniEnv())->GetObjectField(*object, fieldId);
+ }
+
+ static inline jint getIntFieldFromClass(jobject* object, const char* fieldName, const char* fieldSig) {
+ jfieldID fieldId = getFieldIDFromObject(object, fieldName, fieldSig);
+ return (*JniUtils::getJniEnv())->GetIntField(*object, fieldId);
+ }
+
+ static inline void setObjectField(jobject* object, const char* fieldName, const char* fieldSig, jobject value) {
+ jfieldID fieldId = getFieldIDFromObject(object, fieldName, fieldSig);
+ (*JniUtils::getJniEnv())->SetObjectField(*object, fieldId, value);
+ }
+
+ static inline void setIntField(jobject* object, const char* fieldName, const char* fieldSig, jint value) {
+ jfieldID fieldId = getFieldIDFromObject(object, fieldName, fieldSig);
+ (*JniUtils::getJniEnv())->SetIntField(*object, fieldId, value);
+ }
+
+ /**
+ * Translates a java TerminalDevice object into a native TerminalDevice object.
+ *
+ * @param object a pointer referring to the java TerminalDevice object.
+ * @return a native terminal device holding the jdk terminal device's data.
+ */
+ static inline jobject getSerialPortFromTerminalDevice(jobject* object) {
+ return getObjectFieldFromClass(object, "serialPort", "Lcom/serial4j/core/serial/SerialPort;");
+ }
+
+ static inline int getPortDescriptorFromSerialPort(jobject* object) {
+ jobject serialPortObject = getSerialPortFromTerminalDevice(object);
+ return getIntFieldFromClass(&serialPortObject, "fd", "I");
+ }
+
+ static inline jobjectArray createNewArrayFromBuffer(const char* clazzName, jsize length) {
+ jobject initialElement = (*JniUtils::getJniEnv())->NewStringUTF("");
+
+ jclass clazz = JniUtils::getClassFromString(clazzName);
+ jobjectArray array = (*JniUtils::getJniEnv())->NewObjectArray(length, clazz, initialElement);
+ return array;
+ }
+
+ static inline jobject* getObjectBufferFromString(const char** buffer, int length) {
+ jobject* objectBuffer = (jobject*) calloc(length, sizeof(jobject));
+ for (int i = 0; i < length; i++) {
+ objectBuffer[i] = (*JniUtils::getJniEnv())->NewStringUTF(buffer[i]);
+ }
+ return objectBuffer;
+ }
+
+ static inline const char* getBufferFromString(jstring string) {
+ return (*JniUtils::getJniEnv())->GetStringUTFChars(string, 0);
+ }
+
+ static inline jstring getStringFromBuffer(const char* buffer) {
+ return (*JniUtils::getJniEnv())->NewStringUTF(buffer);
+ }
+
+ static inline void setArrayElements(jobjectArray array, jsize length, jobject* buffer) {
+ for (int i = 0; i < length; i++) {
+ (*JniUtils::getJniEnv())->SetObjectArrayElement(array, i, buffer[i]);
+ }
+ }
+
+ static inline jobject getArrayElement(jobjectArray* array, jsize index) {
+ return (*JniUtils::getJniEnv())->GetObjectArrayElement(*array, index);
+ }
+
+ static inline jint getIntArrayElement(jintArray* array, jsize index) {
+ return (*JniUtils::getJniEnv())->GetIntArrayElements(*array, 0)[index];
+ }
+
+ static inline jbyte* getByteArrayElement(jbyteArray* array, jsize index) {
+ return (*JniUtils::getJniEnv())->GetByteArrayElements(*array, 0);
+ }
+
+ static inline jintArray getIntArrayFromBuffer(int* buffer, int length) {
+ jintArray intArray = (*JniUtils::getJniEnv())->NewIntArray(length);
+ (*JniUtils::getJniEnv())->SetIntArrayRegion(intArray, 0, length, buffer);
+ return intArray;
+ }
+
+ static inline jbyteArray getByteArrayFromBuffer(signed char* buffer, int length) {
+ jbyteArray byetArray = (*JniUtils::getJniEnv())->NewByteArray(length);
+ (*JniUtils::getJniEnv())->SetByteArrayRegion(byetArray, 0, length, buffer);
+ return byetArray;
+ }
+
+ static inline jcharArray getCharArrayFromBuffer(jchar* buffer, int length) {
+ jcharArray charArray = (*JniUtils::getJniEnv())->NewCharArray(length);
+ (*JniUtils::getJniEnv())->SetCharArrayRegion(charArray, 0, length, buffer);
+ return charArray;
+ }
+
+ static inline jbooleanArray getBooleanArrayFromBuffer(jboolean* buffer, int length) {
+ jbooleanArray booleanArray = (*JniUtils::getJniEnv())->NewBooleanArray(length);
+ (*JniUtils::getJniEnv())->SetBooleanArrayRegion(booleanArray, 0, length, buffer);
+ return booleanArray;
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/Logger.h b/HelloSerial4j/src/main/native/include/Logger.h
new file mode 100644
index 00000000..bf3f28ad
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/Logger.h
@@ -0,0 +1,73 @@
+#ifndef LOGGER
+
+#define LOGGER
+
+#include
+#include
+#include
+#include
+#include
+
+typedef const char* AlertType;
+
+#define INFO ((AlertType) "Info")
+#define WARNING ((AlertType) "Warning")
+#define OK ((AlertType) "Status Ok")
+#define FAILURE ((AlertType) "Failed")
+#define SUCCESS ((AlertType) "Succeeded")
+
+#define LOGGER_FORMAT ((const char*) "%s::%s: %s \n\r")
+
+struct Logger {
+
+ int* loggingEnabled;
+
+ void init() {
+ loggingEnabled = (int*) calloc(1, sizeof(int*));
+ }
+
+ void destroy() {
+ BufferUtils::deleteBuffer(loggingEnabled);
+ }
+
+ void setLoggingEnabled() {
+ *(this->loggingEnabled) = 1;
+ }
+
+ void setLoggingDisabled() {
+ *(this->loggingEnabled) = 0;
+ }
+
+ int* isLoggingEnabled() {
+ return this->loggingEnabled;
+ }
+
+ int LOG(const char* API_LABEL, AlertType ALERT_TYPE, const char* MSG) {
+ if (!*(this->isLoggingEnabled())) {
+ return LOGGER_DISABLED;
+ }
+ return printf(LOGGER_FORMAT, API_LABEL, ALERT_TYPE, MSG);
+ }
+
+ int LOGI(const char* API_LABEL, const char* MSG) {
+ return LOG(API_LABEL, INFO, MSG);
+ }
+
+ int LOGW(const char* API_LABEL, const char* MSG) {
+ return LOG(API_LABEL, WARNING, MSG);
+ }
+
+ int LOGF(const char* API_LABEL, const char* MSG) {
+ return LOG(API_LABEL, FAILURE, MSG);
+ }
+
+ int LOGS(const char* API_LABEL, const char* MSG) {
+ return LOG(API_LABEL, SUCCESS, MSG);
+ }
+
+ int LOG_OK(const char* API_LABEL, const char* MSG) {
+ return LOG(API_LABEL, OK, MSG);
+ }
+};
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/info.md b/HelloSerial4j/src/main/native/include/info.md
new file mode 100644
index 00000000..b69ea01a
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/info.md
@@ -0,0 +1,8 @@
+# Serial4j API C Utils
+
+## Includes the following:
+- BufferUtils.h: for managing native buffers.
+- DynamicBuffer.h: for creating dynamic buffers.
+- ErrnoUtils.h: for checking and referencing different errno code numbers.
+- JniUtils.h: for java native interface utilities.
+- Logger.h: for native logging using {printf}.
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_errno_NativeErrno.h b/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_errno_NativeErrno.h
new file mode 100644
index 00000000..5356cc8e
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_errno_NativeErrno.h
@@ -0,0 +1,173 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include
+/* Header for class com_serial4j_core_errno_NativeErrno */
+
+#ifndef _Included_com_serial4j_core_errno_NativeErrno
+#define _Included_com_serial4j_core_errno_NativeErrno
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getBadFileDescriptorErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getBadFileDescriptorErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getBrokenPipeErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getBrokenPipeErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getFileAlreadyOpenedErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileAlreadyOpenedErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getFileIsDirectoryErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileIsDirectoryErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getFileTableOverflowErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileTableOverflowErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getFileTooLargeErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileTooLargeErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getInputOutputErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInputOutputErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getInterruptedSystemCallErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInterruptedSystemCallErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getInvalidArgumentErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInvalidArgumentErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getInvalidPortErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInvalidPortErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getNoAvailableTtyDevicesErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoAvailableTtyDevicesErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getNoSpaceLeftErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSpaceLeftErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getNoSuchDeviceErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSuchDeviceErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getNoSuchFileErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSuchFileErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getNotTtyDeviceErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNotTtyDeviceErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getOperationFailedErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getOperationFailedErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getPermissionDeniedErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getPermissionDeniedErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getReadOnlyFileSystemErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getReadOnlyFileSystemErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getTooManyOpenedFilesErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getTooManyOpenedFilesErrno
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_errno_NativeErrno
+ * Method: getTryAgainErrno
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getTryAgainErrno
+ (JNIEnv *, jclass);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_serial_NativeTerminalDevice.h b/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_serial_NativeTerminalDevice.h
new file mode 100644
index 00000000..71264988
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/jni/com_serial4j_core_serial_NativeTerminalDevice.h
@@ -0,0 +1,189 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include
+/* Header for class com_serial4j_core_serial_NativeTerminalDevice */
+
+#ifndef _Included_com_serial4j_core_serial_NativeTerminalDevice
+#define _Included_com_serial4j_core_serial_NativeTerminalDevice
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setupJniEnvironment0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setupJniEnvironment0
+ (JNIEnv *, jclass);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setTerminalControlFlag
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalControlFlag
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setTerminalLocalFlag
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalLocalFlag
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setTerminalInputFlag
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalInputFlag
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setTerminalOutputFlag
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalOutputFlag
+ (JNIEnv *, jobject, jlong);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getTerminalControlFlag
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalControlFlag
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getTerminalLocalFlag
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalLocalFlag
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getTerminalInputFlag
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalInputFlag
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getTerminalOutputFlag
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalOutputFlag
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setReadConfigurationMode0
+ * Signature: (II)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setReadConfigurationMode0
+ (JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getReadConfigurationMode0
+ * Signature: ()[I
+ */
+JNIEXPORT jintArray JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getReadConfigurationMode0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getErrno0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getErrno0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: fetchSerialPorts0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_fetchSerialPorts0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: getBaudRate0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getBaudRate0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: writeData0
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_writeData0
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: readData0
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_readData0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: writeBuffer0
+ * Signature: (Ljava/lang/String;I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_writeBuffer0
+ (JNIEnv *, jobject, jstring, jint);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: readBuffer0
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_readBuffer0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: openPort0
+ * Signature: (Ljava/lang/String;I)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_openPort0
+ (JNIEnv *, jobject, jstring, jint);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: initTermios0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_initTermios0
+ (JNIEnv *, jobject);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: setBaudRate0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setBaudRate0
+ (JNIEnv *, jobject, jint);
+
+/*
+ * Class: com_serial4j_core_serial_NativeTerminalDevice
+ * Method: closePort0
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_closePort0
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/HelloSerial4j/src/main/native/include/jni/info.md b/HelloSerial4j/src/main/native/include/jni/info.md
new file mode 100644
index 00000000..81652f87
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/jni/info.md
@@ -0,0 +1,4 @@
+# Serial4j API Native Jni headers
+
+## Includes the following:
+- {com_serial4j_core_serial_NativeTerminalDevice.h}: for terminal device operation and initialization.
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/linux/SerialUtils.h b/HelloSerial4j/src/main/native/include/linux/SerialUtils.h
new file mode 100644
index 00000000..1a72934c
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/linux/SerialUtils.h
@@ -0,0 +1,77 @@
+/**
+ * @file SerialUtils.util
+ * @author pavl_g.
+ * @brief Represents utilities for the [Serial.h] library.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SERIAL_UTILS
+#define SERIAL_UTILS
+
+#include
+#include
+#include
+#include
+#include
+
+namespace SerialUtils {
+
+ /**
+ * @brief Converts a [file] into a [device] and outputs the
+ * result into a [buffer].
+ *
+ * @param buffer a buffer to fill in the operation.
+ * @param file the file to convert into a device.
+ * @return char* a buffer of {"/dev/"} formula.
+ */
+ static inline char* concatIntoDevice(char* buffer, const char* file, const char* DEVICES_DIR) {
+ strcat(buffer, DEVICES_DIR);
+ strcat(buffer, file);
+ return buffer;
+ }
+
+ /**
+ * @brief Tests whether the PATH specified is a real serial port.
+ *
+ * @param path the path to specify if its a serial port.
+ * @return int 1 if FD is a valid descriptor, 0 otherwise.
+ */
+ static inline int isSerialPort(char* path, const int FLAG) {
+ int fdp = open(path, FLAG);
+ int state = isatty(fdp);
+ close(fdp);
+ return state;
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/linux/TerminalDevice.h b/HelloSerial4j/src/main/native/include/linux/TerminalDevice.h
new file mode 100644
index 00000000..66b9385d
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/linux/TerminalDevice.h
@@ -0,0 +1,258 @@
+/**
+ * @file Serial.h
+ * @author pavl_g.
+ * @brief Represents the serial port devices control and operation for POSIX systems.
+ * @note This is the base [HAL] (Hardware abstraction layer) for the Serial4j api.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SERIAL
+#define SERIAL "Serial4j-API"
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#define READ_CONFIG_SIZE (2)
+#define DEVICES_DIR ((const char*) "/dev/")
+
+/** The default flags for the base file api */
+#define DEFAULT_FLAGS (O_RDWR | O_NONBLOCK | O_NOCTTY)
+
+typedef unsigned short int TerminalFlag;
+
+namespace TerminalDevice {
+
+ /** Param@0 = VTIME, Param@1 = VMIN */
+ const cc_t POLLING_READ[READ_CONFIG_SIZE] = {0, 0};
+ const cc_t BLOCKING_READ_ONE_CHAR[READ_CONFIG_SIZE] = {0, 1};
+ const cc_t READ_WITH_TIMEOUT[READ_CONFIG_SIZE] = {1, 0};
+ const cc_t READ_WITH_INTERBYTE_TIMEOUT[READ_CONFIG_SIZE] = {1, 1};
+
+ /**
+ * Retrieves the termios of this tty device described by the file descriptor (fd).
+ *
+ * @param fd the virtual file descriptor for this tty device.
+ * @return a memory reference to the termios defining this tty device terminal attributes.
+ */
+ struct termios* getTermiosFromFd(int* fd);
+
+ /**
+ * @brief Fetches serial port devices on "/dev/" into [serialPorts] buffer.
+ * @note Uses , , , and .
+ *
+ * @return int (-3) if the directory ["/dev"] is invalid, (-4) if there are no tty
+ * devices available at the ["/dev"] directory, (1) if operation succeeded.
+ */
+ int fetchSerialPorts(struct DynamicBuffer* serialPorts);
+
+ /**
+ * @brief Opens a serial port device with a name.
+ * @note Uses Unix file base api and .
+ *
+ * @param port the path for the serial port device.
+ * @return int* a memory reference for the port file descriptor.
+ */
+ int openPort(const char* port, int flag);
+
+ /**
+ * @brief Initializes the default terminal for this device with the following default charachteristics:
+ * -----------
+ * # c_cflag: for control mode flags.
+ * *** Enable these bits:
+ * - [CREAD]: Allow input to be received.
+ * - [CS8]: For charachter size 8-bit, you can use the bit mask CSIZE to read this value.
+ * - [CLOCAL]: Ignore modem status lines (donÂ’t check carrier signal).
+ * -----------
+ * # c_lflag: for local mode flags.
+ * ***Disable these bits:
+ * - [ICANON]: Canonical mode (line-by-line) input.
+ * - [ECHO]: Echo input characters.
+ * - [ECHOE]: Perform ERASE visually.
+ * - [ECHOK]: Echo KILL visually.
+ * - [ECHOKE]: DonÂ’t output a newline after echoed KILL.
+ * - [ECHONL]: Echo NL (in canonical mode) even if echoing is disabled.
+ * - [ECHOPRT]: Echo deleted characters backward (between \ and / ).
+ * - [ECHOCTL]: Echo control characters visually (e.g., ^L ).
+ * - [ISIG]: Enable signal-generating characters (INTR, QUIT, SUSP).
+ * - [IEXTEN]: Enable extended processing of input characters.
+ * -----------
+ * # c_oflag: for output mode flags.
+ * ***Disable these bits:
+ * - [OPOST]: Perform output postprocessing.
+ * - [ONLCR]: Map NL to CR-NL on output.
+ * -----------
+ * # c_iflag: for input mode flags.
+ * ***Disable all input bit masks.
+ * -----------
+ * # c_cc: For control characters.
+ * ***Sets to BLOCKING READ ONE CHAR AT A TIME MODE.
+ * -----------
+ *
+ * @return int (-1) for failure, (-2) for invalid port or (1) for success.
+ */
+ int initTermios(int* fd);
+
+ /**
+ * @brief Sets the Terminal Control Flag [c_cflag] for the [termios] variable.
+ *
+ * @param flag bits to set, concatenate the flags using bitwise OR [|].
+ * @return int (-1) for failure, (-2) for invalid port or (1) for success.
+ */
+ int setTerminalControlFlag(TerminalFlag flag, int* fd);
+
+ /**
+ * @brief Sets the Terminal Local Flag [c_lflag] for the [termios] variable.
+ *
+ * @param flag bits to set, concatenate the flags using bitwise OR [|].
+ * @return int (-1) for failure, (-2) for invalid port or (1) for success.
+ */
+ int setTerminalLocalFlag(TerminalFlag flag, int* fd);
+
+ /**
+ * @brief Sets the Terminal Output Flag [c_oflag] for the [termios] variable.
+ *
+ * @param flag bits to set, concatenate the flags using bitwise OR [|].
+ * @return int (-1) for failure, (-2) for invalid port or (1) for success.
+ */
+ int setTerminalOutputFlag(TerminalFlag flag, int* fd);
+
+ /**
+ * @brief Sets the Terminal Input Flag [c_iflag] for the [termios] variable.
+ *
+ * @param flags bits to set, concatenate the flags using bitwise OR [|].
+ * @return int (-1) for failure, (-2) for invalid port or (1) for success.
+ */
+ int setTerminalInputFlag(TerminalFlag flag, int* fd);
+
+ /**
+ * @brief Gets the Terminal Control Flag defined by the termios attributes for this serial device.
+ *
+ * @return TerminalFlag the terminal control flag in [unsigned short int].
+ */
+ TerminalFlag getTerminalControlFlag(int* fd);
+
+ /**
+ * @brief Gets the Terminal Local Flag defined by the termios attributes for this serial device.
+ *
+ * @return TerminalFlag the terminal local flag in [unsigned short int].
+ */
+ TerminalFlag getTerminalLocalFlag(int* fd);
+
+ /**
+ * @brief Gets the Terminal Input Flag defined by the termios attributes for this serial device.
+ *
+ * @return TerminalFlag the terminal input flag in [unsigned short int].
+ */
+ TerminalFlag getTerminalInputFlag(int* fd);
+
+ /**
+ * @brief Gets the Terminal Output Flag defined by the termios attributes for this serial device.
+ *
+ * @return TerminalFlag the terminal output flag in [unsigned short int].
+ */
+ TerminalFlag getTerminalOutputFlag(int* fd);
+
+ /**
+ * @brief Sets the Read Configuration Mode using a ReadConfiguration with a
+ * VMIN_VALUE for lesser bytes to read and VTIME_VALUE for the elapsed time to
+ * set if the ReadConfiguration mode provides a timeout.
+ *
+ * @param VTIME_VALUE the value of the read timeout elapsed time, the timer starts
+ * with this value after read() is called.
+ * @param VMIN_VALUE the value of the minimum number of bytes to read.
+ * @return int (ERR_INVALID_PORT = -2) if port isn't available, (0) otherwise.
+ */
+ int setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd);
+
+ /**
+ * @brief Get the Read Configuration Mode in a new pointer.
+ *
+ * @return int* a memory reference to the new read configuration instance holding the VTIME and VMIN.
+ */
+ cc_t* getReadConfigurationMode(int* fd);
+
+ /**
+ * @brief Sets the Baud Rate object for the terminal io.
+ *
+ * @param baudRate the baud rate (bits/seconds).
+ * @return int (1) for success, (-1) for failure, (-2) for invalid port.
+ */
+ int setBaudRate(int baudRate, int* fd);
+
+ /**
+ * @brief Gets the Baud Rate object.
+ *
+ * @return speed_t baud rate in integers.
+ */
+ speed_t getBaudRate(int* fd);
+
+ /**
+ * @brief Writes a data to the serial port device from a buffer.
+ *
+ * @param buffer a buffer to write to the file.
+ * @param length the number of charachters to write from the buffer.
+ * @return ssize_t the number of bytes written to the serial device, (-1) for failure, (-2) for invalid port.
+ */
+ ssize_t writeData(const void* buffer, int length, int* fd);
+
+ /**
+ * @brief Reads data from the serial port device and saves it to a buffer.
+ *
+ * @param buffer a buffer to read from the file to it.
+ * @param length the number of the charachters to read by this buffer.
+ * @return ssize_t the number of bytes read from the terminal, (-1) for failure, (-2) for invalid port.
+ */
+ ssize_t readData(void* buffer, int length, int* fd);
+
+ /**
+ * @brief Closes the serial port device.
+ *
+ * @return int (1) for success, (-1) for failure, (-2) for invalid port.
+ */
+ int closePort(int* fd);
+
+}
+
+
+#endif
diff --git a/HelloSerial4j/src/main/native/include/linux/Thread.h b/HelloSerial4j/src/main/native/include/linux/Thread.h
new file mode 100644
index 00000000..7b57ec42
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/linux/Thread.h
@@ -0,0 +1,51 @@
+/**
+ * @file Thread.h
+ * @author pavl_g.
+ * @brief Optional header for operating within PThreads.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @note TODO.
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _THREADS
+#define _THREADS
+
+#include
+
+namespace POSIX {
+ struct Thread {
+
+ };
+}
+
+#endif
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/linux/info.md b/HelloSerial4j/src/main/native/include/linux/info.md
new file mode 100644
index 00000000..615ff40e
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/linux/info.md
@@ -0,0 +1 @@
+# Serial4j API Native Side designed for Linux/Unix
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/include/windows/info.md b/HelloSerial4j/src/main/native/include/windows/info.md
new file mode 100644
index 00000000..5cac7b1e
--- /dev/null
+++ b/HelloSerial4j/src/main/native/include/windows/info.md
@@ -0,0 +1 @@
+# Serial4j API Win Side
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/lib/DynamicBuffer.c b/HelloSerial4j/src/main/native/lib/DynamicBuffer.c
new file mode 100755
index 00000000..0bd13205
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/DynamicBuffer.c
@@ -0,0 +1,62 @@
+#include
+
+void DynamicBuffer::add(void* item) {
+
+ /* move the pointer to point to the last item */
+ /* then, obtain a superficial copy */
+ void** copy = (buffer += count);
+ /* dereference and evalute using the superficial copy */
+ *copy = (void*) calloc(1, sizeof(void*));
+ *copy = item;
+ /* move the pointer back to the start of the buffer (first item) */
+ buffer -= count;
+ count++;
+}
+
+void DynamicBuffer::add(int index, void* item) {
+ /* adds on the count if the location was empty previously */
+ if (buffer[index] == NULL) {
+ ++count;
+ }
+ buffer[index] = item;
+}
+
+void DynamicBuffer::removeAt(int index) {
+ BufferUtils::nullifyBuffer(buffer, index);
+ BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed));
+
+ while (!this->isProcessed);
+ this->isProcessed = 0;
+
+ count--;
+}
+
+void DynamicBuffer::removeAll() {
+ for (int i = 0; i < *(this->getItemsCount()); i++) {
+ BufferUtils::nullifyBuffer(buffer, i);
+ }
+
+ BufferUtils::reValidateBuffer(buffer, getItemsCount(), &(this->isProcessed));
+
+ while (!this->isProcessed);
+ this->isProcessed = 0;
+
+ this->resetDataPointer();
+}
+
+void* DynamicBuffer::getItem(int index) {
+ return buffer[index];
+}
+
+int DynamicBuffer::getItemIndex(void* item) {
+ for (int i = 0; i < *getItemsCount(); i++) {
+ if (buffer[i] == item) {
+ return i;
+ }
+ }
+ return ERR_OPERATION_FAILED;
+}
+
+int* DynamicBuffer::getItemsCount() {
+ return &count;
+}
diff --git a/HelloSerial4j/src/main/native/lib/info.md b/HelloSerial4j/src/main/native/lib/info.md
new file mode 100644
index 00000000..d9a935a6
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/info.md
@@ -0,0 +1,4 @@
+# Serial4j API C Utils
+
+## Includes the following:
+- DynamicBuffer.c: for creating dynamic buffers.
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_errno_NativeErrno.c b/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_errno_NativeErrno.c
new file mode 100755
index 00000000..aa6e263f
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_errno_NativeErrno.c
@@ -0,0 +1,102 @@
+#include
+#include
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getBadFileDescriptorErrno
+ (JNIEnv* env, jclass clazz) {
+ return EBADFD;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getBrokenPipeErrno
+ (JNIEnv* env, jclass clazz) {
+ return EPIPE;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileAlreadyOpenedErrno
+ (JNIEnv* env, jclass clazz) {
+ return EEXIST;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileIsDirectoryErrno
+ (JNIEnv* env, jclass clazz) {
+ return EISDIR;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileTableOverflowErrno
+ (JNIEnv* env, jclass clazz) {
+ return ENFILE;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getFileTooLargeErrno
+ (JNIEnv* env, jclass clazz) {
+ return EFBIG;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInputOutputErrno
+ (JNIEnv* env, jclass clazz) {
+ return EIO;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInterruptedSystemCallErrno
+ (JNIEnv* env, jclass clazz) {
+ return EINTR;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInvalidArgumentErrno
+ (JNIEnv* env, jclass clazz) {
+ return EINVAL;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getInvalidPortErrno
+ (JNIEnv* env, jclass clazz) {
+ return ERR_INVALID_PORT;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoAvailableTtyDevicesErrno
+ (JNIEnv* env, jclass clazz) {
+ return ERR_NO_AVAILABLE_TTY_DEVICES;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSpaceLeftErrno
+ (JNIEnv* env, jclass clazz) {
+ return ENOSPC;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSuchDeviceErrno
+ (JNIEnv* env, jclass clazz) {
+ return ENXIO;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNoSuchFileErrno
+ (JNIEnv* env, jclass clazz) {
+ return ENOENT;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getNotTtyDeviceErrno
+ (JNIEnv* env, jclass clazz) {
+ return ERR_NO_AVAILABLE_TTY_DEVICES;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getOperationFailedErrno
+ (JNIEnv* env, jclass clazz) {
+ return ERR_OPERATION_FAILED;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getPermissionDeniedErrno
+ (JNIEnv* env, jclass clazz) {
+ return EACCES;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getReadOnlyFileSystemErrno
+ (JNIEnv* env, jclass clazz) {
+ return EROFS;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getTooManyOpenedFilesErrno
+ (JNIEnv* env, jclass clazz) {
+ return EMFILE;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_errno_NativeErrno_getTryAgainErrno
+ (JNIEnv* env, jclass clazz) {
+ return EAGAIN;
+}
diff --git a/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_serial_NativeTerminalDevice.c b/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_serial_NativeTerminalDevice.c
new file mode 100755
index 00000000..350b4f93
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/jni/com_serial4j_core_serial_NativeTerminalDevice.c
@@ -0,0 +1,238 @@
+/**
+ * @file com_serial4j_core_serial_NativeTerminalDevice.c
+ * @author pavl_g.
+ * @brief Instantiates a native interface of Serial4j API for the java programming language.
+ * @version 0.1
+ * @date 2022-09-06
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project, Serial4j API.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#include
+
+struct DynamicBuffer serialPorts;
+cc_t* config = (cc_t*) calloc(2, sizeof(cc_t));
+
+const cc_t* getReadConfiguration(jobject* object);
+
+const cc_t* getReadConfiguration(jobject* object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(object);
+ const cc_t* readConfigBuffer = TerminalDevice::getReadConfigurationMode(&fd);
+ return readConfigBuffer;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setupJniEnvironment0
+ (JNIEnv* env, jclass clazz) {
+ return JniUtils::setupJavaEnvironment(env, JNI_VERSION_1_8);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalControlFlag
+ (JNIEnv* env, jobject object, jlong flag) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::setTerminalControlFlag((jlong) flag, &fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalLocalFlag
+ (JNIEnv* env, jobject object, jlong flag) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::setTerminalLocalFlag((jlong) flag, &fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalInputFlag
+ (JNIEnv* env, jobject object, jlong flag) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::setTerminalInputFlag((jlong) flag, &fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setTerminalOutputFlag
+ (JNIEnv* env, jobject object, jlong flag) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::setTerminalOutputFlag((jlong) flag, &fd);
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalControlFlag
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return (jlong) TerminalDevice::getTerminalControlFlag(&fd);
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalLocalFlag
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return (jlong) TerminalDevice::getTerminalLocalFlag(&fd);
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalInputFlag
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return (jlong) TerminalDevice::getTerminalInputFlag(&fd);
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getTerminalOutputFlag
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return (jlong) TerminalDevice::getTerminalOutputFlag(&fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setReadConfigurationMode0
+ (JNIEnv* env, jobject object, jint timeoutValue, jint minimumBytes) {
+
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+
+ return TerminalDevice::setReadConfigurationMode(timeoutValue, minimumBytes, &fd);
+}
+
+JNIEXPORT jintArray JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getReadConfigurationMode0
+ (JNIEnv* env, jobject object) {
+ const cc_t* readConfig = getReadConfiguration(&object);
+ int* buffer = (int*) calloc(2, sizeof(int));
+ buffer[0] = readConfig[0];
+ buffer[1] = readConfig[1];
+ return JniUtils::getIntArrayFromBuffer(buffer, READ_CONFIG_SIZE);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_fetchSerialPorts0
+ (JNIEnv* env, jobject object) {
+ int state = TerminalDevice::fetchSerialPorts(&serialPorts);
+
+ int length = *serialPorts.getItemsCount();
+ jobjectArray stringArray = JniUtils::createNewArrayFromBuffer(java_lang_String, length);
+ JniUtils::setObjectField(&object, "serialPorts", "[Ljava/lang/String;", stringArray);
+
+ jobject* objectBuffer = JniUtils::getObjectBufferFromString((const char**) serialPorts.getBuffer(), length);
+ JniUtils::setArrayElements(stringArray, length, objectBuffer);
+ BufferUtils::deleteBuffer(objectBuffer);
+
+ return state;
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_writeData0
+ (JNIEnv* env, jobject object, jint buffer) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::writeData(&buffer, 1, &fd);
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_readData0
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ int length = getReadConfiguration(&object)[1] <= 0 ? getReadConfiguration(&object)[1] : 1;
+
+ jchar* buffer = (jchar*) calloc(length, sizeof(jchar));
+ int state = TerminalDevice::readData((void*) buffer, length, &fd);
+
+ jcharArray arrayBuffer = JniUtils::getCharArrayFromBuffer(buffer, length);
+ JniUtils::setObjectField(&object, "readData", "[C", arrayBuffer);
+
+ BufferUtils::deleteBuffer(buffer);
+ return state;
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_writeBuffer0
+ (JNIEnv* env, jobject object, jstring string, jint length) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ const char* buffer = JniUtils::getBufferFromString(string);
+ int state = TerminalDevice::writeData(buffer, length, &fd);
+ BufferUtils::deleteBuffer((void*) buffer);
+ return state;
+}
+
+JNIEXPORT jlong JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_readBuffer0
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ /* construct a termios and get the control charachter flag from fd */
+ struct termios* tty = TerminalDevice::getTermiosFromFd(&fd);
+
+ int length = tty->c_cc[VMIN];
+
+ const char* strBuffer = (const char*) calloc(length, sizeof(const char));
+
+ long numberOfReadChars = TerminalDevice::readData((void*) strBuffer, length, &fd);
+
+ /* get the java string buffer and setup its data with the buffer */
+ JniUtils::setObjectField(&object, "readBuffer", "Ljava/lang/String;", (*JniUtils::getJniEnv())->NewStringUTF(strBuffer));
+
+ BufferUtils::deleteBuffer(tty);
+ BufferUtils::deleteBuffer((void*) strBuffer);
+
+
+ return numberOfReadChars;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_setBaudRate0
+ (JNIEnv* env, jobject object, jint baudRate) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::setBaudRate(baudRate, &fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getBaudRate0
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::getBaudRate(&fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_initTermios0
+ (JNIEnv* env, jobject object) {
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ return TerminalDevice::initTermios(&fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_openPort0
+ (JNIEnv* env, jobject object, jstring strBuffer, jint flag) {
+
+ int fd = TerminalDevice::openPort((*JniUtils::getJniEnv())->GetStringUTFChars(strBuffer, 0), flag);
+ jobject serialPortObject = JniUtils::getSerialPortFromTerminalDevice(&object);
+ JniUtils::setIntField(&serialPortObject, "portOpened", "I", 1);
+ JniUtils::setIntField(&serialPortObject, "fd", "I", fd);
+ JniUtils::setIntField(&serialPortObject, "ioFlag", "I", flag);
+
+ return fd;
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_closePort0
+ (JNIEnv* env, jobject object) {
+
+ jobject serialPortObject = JniUtils::getSerialPortFromTerminalDevice(&object);
+
+ jint fd = JniUtils::getPortDescriptorFromSerialPort(&object);
+ JniUtils::setIntField(&serialPortObject, "portOpened", "I", 0);
+ JniUtils::setIntField(&serialPortObject, "fd", "I", 0);
+ JniUtils::setObjectField(&serialPortObject, "path", "Ljava/lang/String;", (*JniUtils::getJniEnv())->NewStringUTF(""));
+
+ return TerminalDevice::closePort(&fd);
+}
+
+JNIEXPORT jint JNICALL Java_com_serial4j_core_serial_NativeTerminalDevice_getErrno0
+ (JNIEnv* env, jobject object) {
+ return errno;
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/lib/linux/TerminalDevice.c b/HelloSerial4j/src/main/native/lib/linux/TerminalDevice.c
new file mode 100755
index 00000000..2de4dad3
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/linux/TerminalDevice.c
@@ -0,0 +1,249 @@
+#include
+
+struct termios* TerminalDevice::getTermiosFromFd(int* fd) {
+ if (fd == NULL) {
+ return NULL;
+ }
+ struct termios* tty = (struct termios*) calloc(1, sizeof(struct termios));
+ /* update the termios struct pointer with the data from the port descriptor */
+ tcgetattr(*fd, tty);
+ return tty;
+}
+
+int TerminalDevice::openPort(const char* port, int flag) {
+ return open(port, flag);
+}
+
+int TerminalDevice::fetchSerialPorts(struct DynamicBuffer* serialPorts) {
+
+ DIR* dirp = opendir(DEVICES_DIR);
+
+ /* sanity check the input */
+ if (dirp == NULL) {
+ return ERR_INVALID_DIR;
+ }
+
+ struct dirent* dp = (struct dirent*) calloc(1, sizeof(struct dirent));
+
+ /* start at the beginning of the buffer to override last data */
+ serialPorts->resetDataPointer();
+
+ /* start reading available ports */
+ while ((dp = readdir(dirp)) != NULL) {
+
+ char* device = (char*) calloc(1, sizeof(char));
+ device = SerialUtils::concatIntoDevice(device, dp->d_name, DEVICES_DIR);
+
+ /* delete the device buffer if it's not a serial port */
+ if (!SerialUtils::isSerialPort(device, DEFAULT_FLAGS)) {
+ BufferUtils::deleteBuffer(device);
+ continue;
+ }
+
+ /* add the device to the serial ports major buffer and count up */
+ serialPorts->add(device);
+ }
+
+ /* release resources */
+ closedir(dirp);
+ BufferUtils::deleteBuffer(dp);
+
+ /* throws error indicating the availability issues */
+ if (serialPorts->getItem(0) == NULL) {
+ return ERR_NO_AVAILABLE_TTY_DEVICES;
+ }
+ return OPERATION_SUCCEEDED;
+}
+
+int TerminalDevice::initTermios(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ /* setup tty attributes */
+ tty->c_cflag &= ~(CBAUDEX | CBAUD); /* clear BAUDs */
+ tty->c_cflag |= (CREAD | CS8 | CLOCAL); /* set flags */
+ tty->c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT | ECHOCTL | ISIG | IEXTEN);
+ tty->c_oflag &= ~(OPOST | ONLCR);
+ tty->c_iflag = 0x00;
+
+ /* define default read mode as blocking read on char at a time */
+ tty->c_cc[VTIME] = BLOCKING_READ_ONE_CHAR[0];
+ tty->c_cc[VMIN] = BLOCKING_READ_ONE_CHAR[1];
+
+ /* apply attriutes flag bits */
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+int TerminalDevice::setTerminalControlFlag(TerminalFlag flag, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ tty->c_cflag = flag;
+ /* sets the new terminal settings to the file descriptor with flushing any output */
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+int TerminalDevice::setTerminalLocalFlag(TerminalFlag flag, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ tty->c_lflag = flag;
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+int TerminalDevice::setTerminalInputFlag(TerminalFlag flag, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ tty->c_iflag = flag;
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+int TerminalDevice::setTerminalOutputFlag(TerminalFlag flag, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ tty->c_oflag = flag;
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+TerminalFlag TerminalDevice::getTerminalControlFlag(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ return tty->c_cflag;
+}
+
+TerminalFlag TerminalDevice::getTerminalLocalFlag(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ return tty->c_lflag;
+}
+
+TerminalFlag TerminalDevice::getTerminalInputFlag(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ return tty->c_iflag;
+}
+
+TerminalFlag TerminalDevice::getTerminalOutputFlag(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ return tty->c_oflag;
+}
+
+int TerminalDevice::setReadConfigurationMode(const int VTIME_VALUE, const int VMIN_VALUE, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ tty->c_cc[VTIME] = VTIME_VALUE;
+ tty->c_cc[VMIN] = VMIN_VALUE;
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+cc_t* TerminalDevice::getReadConfigurationMode(int* fd) {
+ cc_t* readConfig = (cc_t*) calloc(2, sizeof(unsigned char));
+ if (*fd <= 0) {
+ readConfig[0] = ERR_INVALID_PORT;
+ readConfig[1] = ERR_INVALID_PORT;
+ return readConfig;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ readConfig[0] = tty->c_cc[VTIME];
+ readConfig[1] = tty->c_cc[VMIN];
+ BufferUtils::deleteBuffer(tty);
+
+ return readConfig;
+}
+
+int TerminalDevice::setBaudRate(int baudRate, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ /* update the baud rate of the termios */
+ cfsetspeed(tty, baudRate);
+ int state = tcsetattr(*fd, TCSAFLUSH, tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return state;
+}
+
+speed_t TerminalDevice::getBaudRate(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ struct termios* tty = TerminalDevice::getTermiosFromFd(fd);
+
+ int speed = cfgetospeed(tty);
+ BufferUtils::deleteBuffer(tty);
+
+ return speed;
+}
+
+ssize_t TerminalDevice::writeData(const void* buffer, int length, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ return write(*fd, buffer, length);
+}
+
+ssize_t TerminalDevice::readData(void* buffer, int length, int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ return read(*fd, buffer, length);
+}
+
+int TerminalDevice::closePort(int* fd) {
+ if (*fd <= 0) {
+ return ERR_INVALID_PORT;
+ }
+ return close(*fd);
+}
\ No newline at end of file
diff --git a/HelloSerial4j/src/main/native/lib/linux/Thread.c b/HelloSerial4j/src/main/native/lib/linux/Thread.c
new file mode 100755
index 00000000..a0dd490f
--- /dev/null
+++ b/HelloSerial4j/src/main/native/lib/linux/Thread.c
@@ -0,0 +1,40 @@
+/**
+ * @file Thread.c
+ * @author pavl_g.
+ * @brief Optional source for operating within PThreads.
+ * @version 0.1
+ * @date 2022-08-24
+ *
+ * @note TODO.
+ *
+ * @copyright
+ * BSD 3-Clause License
+ *
+ * Copyright (c) 2022, Scrappers Team, The AVR-Sandbox Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
\ No newline at end of file