From bbe6188a4812f840c1fb33cc97f7a43ea84bdd16 Mon Sep 17 00:00:00 2001 From: Dariusz Zbyrad Date: Tue, 26 Nov 2024 10:42:23 +0100 Subject: [PATCH] Add Javadoc comments and small refactor code --- .../pi4j/boardinfo/definition/BoardModel.java | 146 ++++++++++++++++-- .../pi4j/boardinfo/definition/BoardType.java | 48 ++++++ .../com/pi4j/boardinfo/definition/Cpu.java | 73 ++++++++- .../pi4j/boardinfo/definition/HeaderPins.java | 140 ++++++++++++++--- .../boardinfo/definition/HeaderVersion.java | 75 +++++++++ .../boardinfo/definition/InstructionSet.java | 58 +++++++ .../pi4j/boardinfo/definition/PiModel.java | 75 ++++++++- .../boardinfo/definition/PinFunction.java | 64 +++++++- .../pi4j/boardinfo/definition/PinType.java | 74 ++++++++- .../com/pi4j/boardinfo/definition/Soc.java | 94 +++++++++++ .../com/pi4j/boardinfo/model/BoardInfo.java | 52 +++++++ .../pi4j/boardinfo/model/BoardReading.java | 101 +++++++++++- .../com/pi4j/boardinfo/model/HeaderPin.java | 116 ++++++++++++-- .../com/pi4j/boardinfo/model/JavaInfo.java | 70 ++++++++- .../com/pi4j/boardinfo/model/JvmMemory.java | 103 ++++++++++-- .../pi4j/boardinfo/model/OperatingSystem.java | 63 +++++++- .../java/com/pi4j/boardinfo/util/Command.java | 2 +- .../boardinfo/definition/BoardModelTest.java | 29 ++++ 18 files changed, 1303 insertions(+), 80 deletions(-) diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java index 85e2d217..933263c1 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardModel.java @@ -1,5 +1,30 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : BoardModel.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,15 +37,15 @@ import static com.pi4j.boardinfo.definition.BoardType.*; /** - * Partially based on: + * Represents various Raspberry Pi board models along with their specifications and attributes. * - * + *

This class is partially based on resources such as Raspberry Pi documentation, GitHub, and other online references.

+ * + * @see Board Codes + * @see Old-style Revision Codes + * @see Raspberry Pi Specifications + * @see How to Identify Your Raspberry Pi + * @see Checking Your Raspberry Pi Board Version */ public enum BoardModel { MODEL_1_A("Raspberry Pi 1 Model A", SINGLE_BOARD_COMPUTER, @@ -277,14 +302,45 @@ public enum BoardModel { private final List versionsMemoryInKb; private final List remarks; + /** + * Constructor for creating a {@code BoardModel} without remarks. + * + * @param label the descriptive name of the board + * @param boardType the type of the board + * @param boardCodes a list of unique codes identifying this board + * @param model the Pi model of the board + * @param headerVersion the header version + * @param releaseDate the release date of the board + * @param soc the system-on-chip used + * @param cpu the CPU type + * @param numberOfCpu the number of CPU cores + * @param versionsProcessorSpeedInMhz list of processor speeds in MHz + * @param versionsMemoryInKb list of memory sizes in KB + */ BoardModel(String label, BoardType boardType, List boardCodes, PiModel model, HeaderVersion headerVersion, LocalDate releaseDate, Soc soc, Cpu cpu, Integer numberOfCpu, List versionsProcessorSpeedInMhz, List versionsMemoryInKb) { - this(label, boardType, boardCodes, model, headerVersion, releaseDate, soc, cpu, numberOfCpu, versionsProcessorSpeedInMhz, - versionsMemoryInKb, new ArrayList<>()); + this(label, boardType, boardCodes, model, headerVersion, releaseDate, soc, cpu, numberOfCpu, + versionsProcessorSpeedInMhz, versionsMemoryInKb, new ArrayList<>()); } + /** + * Constructor for creating a {@code BoardModel}. + * + * @param label the descriptive name of the board + * @param boardType the type of the board + * @param boardCodes a list of unique codes identifying this board + * @param model the Pi model of the board + * @param headerVersion the header version + * @param releaseDate the release date of the board + * @param soc the system-on-chip used + * @param cpu the CPU type + * @param numberOfCpu the number of CPU cores + * @param versionsProcessorSpeedInMhz list of processor speeds in MHz + * @param versionsMemoryInKb list of memory sizes in KB + * @param remarks any remarks or notes about the board + */ BoardModel(String label, BoardType boardType, List boardCodes, PiModel model, HeaderVersion headerVersion, LocalDate releaseDate, Soc soc, Cpu cpu, Integer numberOfCpu, @@ -304,6 +360,13 @@ public enum BoardModel { this.remarks = remarks; } + /** + * Retrieves the board model corresponding to the given board code. + * + * @param boardCode the board code to look up + * @return the matching {@code BoardModel} or {@code UNKNOWN} if no match is found + * @throws Exception if multiple matches are found + */ public static BoardModel getByBoardCode(String boardCode) throws Exception { var matches = Arrays.stream(BoardModel.values()) .filter(bm -> bm.boardCodes.contains(boardCode)) @@ -311,11 +374,17 @@ public static BoardModel getByBoardCode(String boardCode) throws Exception { if (matches.isEmpty()) { return BoardModel.UNKNOWN; } else if (matches.size() > 1) { - throw (new Exception("Too many matching models found for code " + boardCode + ", probably an error in the definitions")); + throw new Exception("Too many matching models found for code " + boardCode); } return matches.get(0); } + /** + * Retrieves the board model corresponding to the given board name. + * + * @param boardName the name of the board + * @return the matching {@code BoardModel} or {@code UNKNOWN} if no match is found + */ public static BoardModel getByBoardName(String boardName) { var matches = Arrays.stream(BoardModel.values()) .filter(bm -> boardName.toLowerCase().startsWith(bm.label.toLowerCase())) @@ -328,69 +397,118 @@ public static BoardModel getByBoardName(String boardName) { return matches.get(0); } + /** + * Retrieves all unique board codes from all models. + * + * @return a list of all board codes + */ public static List getAllBoardCodes() { return Arrays.stream(BoardModel.values()) - .map(b -> b.boardCodes) - .flatMap(List::stream) // Flatten the nested lists into a single stream - .collect(Collectors.toList()); // Collect elements into one list + .flatMap(b -> b.boardCodes.stream()) + .collect(Collectors.toList()); } + /** + * @return the enum name of the board model + */ public String getName() { return name(); } + /** + * @return the label of the board model + */ public String getLabel() { return label; } + /** + * @return the board type + */ public BoardType getBoardType() { return boardType; } + /** + * @return the list of board codes + */ public List getBoardCodes() { return boardCodes; } + /** + * @return the Pi model of the board + */ public PiModel getModel() { return model; } + /** + * @return the header version of the board + */ public HeaderVersion getHeaderVersion() { return headerVersion; } + /** + * @return the release date of the board + */ public LocalDate getReleaseDate() { return releaseDate; } + /** + * @return the system-on-chip used by the board + */ public Soc getSoc() { return soc; } + /** + * @return the CPU type used by the board + */ public Cpu getCpu() { return cpu; } + /** + * @return the number of CPU cores + */ public Integer getNumberOfCpu() { return numberOfCpu; } + /** + * @return a list of processor speeds in MHz + */ public List getVersionsProcessorSpeedInMhz() { return versionsProcessorSpeedInMhz; } + /** + * @return a list of memory sizes in KB + */ public List getVersionsMemoryInKb() { return versionsMemoryInKb; } + /** + * @return a list of memory sizes in MB + */ public List getVersionsMemoryInMb() { return versionsMemoryInKb.stream().map(m -> m / 1024F).collect(Collectors.toList()); } + /** + * @return a list of memory sizes in GB + */ public List getVersionsMemoryInGb() { return versionsMemoryInKb.stream().map(m -> m / 1024F / 1024F).collect(Collectors.toList()); } + /** + * @return any remarks associated with the board + */ public List getRemarks() { return remarks; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardType.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardType.java index 542fe1a7..9db69317 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardType.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/BoardType.java @@ -1,9 +1,57 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : BoardType.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Represents the types of boards available in the Pi4J Board Information API. + */ public enum BoardType { + + /** + * Represents an all-in-one computer board type, such as the Raspberry Pi 400. + */ ALL_IN_ONE_COMPUTER, + + /** + * Represents a microcontroller board type, such as the Raspberry Pi Pico. + */ MICROCONTROLLER, + + /** + * Represents a single-board computer (SBC) type, such as the Raspberry Pi Model B series. + */ SINGLE_BOARD_COMPUTER, + + /** + * Represents a stack-on computer module type, such as the Compute Module series. + */ STACK_ON_COMPUTER, + + /** + * Represents an unknown board type. + */ UNKNOWN } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Cpu.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Cpu.java index 9c275095..c4214a1b 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Cpu.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Cpu.java @@ -1,22 +1,91 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : Cpu.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Represents the Central Processing Unit (CPU) types used in various Raspberry Pi boards and microcontrollers. + */ public enum Cpu { + + /** + * ARM1176JZF-S: A single-core ARM11 processor used in early Raspberry Pi models, such as the Raspberry Pi 1. + */ ARM1176JZF_S("ARM1176JZF-S"), + + /** + * Cortex-A53: A quad-core 64-bit ARM processor used in Raspberry Pi 3 series and similar boards. + */ CORTEX_A53("Cortex-A53"), + + /** + * Cortex-A7: A quad-core ARM processor used in some variants of the Raspberry Pi 2 Model B. + */ CORTEX_A7("Cortex-A7"), + + /** + * Cortex-A72: A quad-core 64-bit ARM processor used in the Raspberry Pi 4 Model B and Compute Module 4. + */ CORTEX_A72("Cortex-A72"), + + /** + * Cortex-A76: A high-performance ARM processor used in the Raspberry Pi 5 Model B. + */ CORTEX_A76("Cortex-A76"), + + /** + * Cortex-M0+: A low-power ARM processor used in Raspberry Pi Pico microcontrollers. + */ CORTEX_MO_PLUS("Cortex-M0+"), + + /** + * Cortex-M33: A high-performance microcontroller processor used in the Raspberry Pi Pico 2 series. + */ CORTEX_M33("Cortex-M33"), - UNKNOWN("Unknown"), - ; + + /** + * Unknown: Represents an unidentified or unsupported CPU type. + */ + UNKNOWN("Unknown"); private final String label; + /** + * Constructs a {@link Cpu} enum constant with the specified label. + * + * @param label the descriptive label for the CPU type. + */ Cpu(String label) { this.label = label; } + /** + * Retrieves the label of the CPU type. + * + * @return the label describing the CPU. + */ public String getLabel() { return label; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderPins.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderPins.java index c304eaad..fa3ac95d 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderPins.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderPins.java @@ -1,64 +1,141 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : HeaderPins.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import com.pi4j.boardinfo.model.HeaderPin; import java.util.ArrayList; import java.util.List; /** - * List of pins in a Raspberry Pi header. + * Represents predefined lists of pins for various Raspberry Pi headers. + * Each header configuration includes details about pin numbers, types, functions, and attributes. */ public enum HeaderPins { + + /** + * 8-pin header configuration. + */ HEADER_8("8pin header", get8PinsHeader()), + + /** + * 26-pin header (type 1) configuration. + */ HEADER_26_TYPE_1("26pin header - type 1", get26PinsHeader(1)), + + /** + * 26-pin header (type 2) configuration. + */ HEADER_26_TYPE_2("26pin header - type 2", get26PinsHeader(2)), + + /** + * 40-pin header configuration. + */ HEADER_40("40pin header", get40PinsHeader()), + + /** + * Compute Module J5 header configuration. + */ COMPUTE_J5("Compute J5", getComputeJ5()), + + /** + * Compute Module J6 header configuration. + */ COMPUTE_J6("Compute J6", getComputeJ6()); private final String label; private final List pins; + /** + * Constructs a {@link HeaderPins} enum constant with a descriptive label and associated pin configuration. + * + * @param label the label describing the header type. + * @param pins the list of pins for the specified header configuration. + */ HeaderPins(String label, List pins) { this.label = label; this.pins = pins; } + /** + * Retrieves the label for the header type. + * + * @return the header label. + */ public String getLabel() { return label; } + /** + * Retrieves the list of pins associated with the header. + * + * @return the pin configuration for the header. + */ public List getPins() { return pins; } + /** + * Generates the 8-pin header configuration. + * + * @return a list of {@link HeaderPin} objects representing the 8-pin header. + */ static List get8PinsHeader() { List header = new ArrayList<>(); - header.add(new HeaderPin(1, PinType.POWER, "5.0 VDC")); - header.add(new HeaderPin(2, PinType.POWER, "3.3 VDC")); + header.add(new HeaderPin(1, PinType.POWER, "5.0 VDC")); + header.add(new HeaderPin(2, PinType.POWER, "3.3 VDC")); header.add(new HeaderPin(3, PinType.DIGITAL, null, 28, 17, "")); header.add(new HeaderPin(4, PinType.DIGITAL, null, 29, 18, "")); header.add(new HeaderPin(5, PinType.DIGITAL, null, 30, 19, "")); header.add(new HeaderPin(6, PinType.DIGITAL, null, 31, 20, "")); - header.add(new HeaderPin(7, PinType.GROUND, "Ground")); - header.add(new HeaderPin(8, PinType.GROUND, "Ground")); + header.add(new HeaderPin(7, PinType.GROUND, "Ground")); + header.add(new HeaderPin(8, PinType.GROUND, "Ground")); return header; } + /** + * Generates the 26-pin header configuration based on the specified type. + * + * @param type the header type (1 or 2) to determine pin mappings. + * @return a list of {@link HeaderPin} objects representing the 26-pin header. + */ static List get26PinsHeader(int type) { List header = new ArrayList<>(); - header.add(new HeaderPin(1, PinType.POWER, "3.3 VDC")); - header.add(new HeaderPin(2, PinType.POWER, "5.0 VDC")); + header.add(new HeaderPin(1, PinType.POWER, "3.3 VDC")); + header.add(new HeaderPin(2, PinType.POWER, "5.0 VDC")); header.add(new HeaderPin(3, PinType.DIGITAL_NO_PULL_DOWN, PinFunction.I2C, (type == 1 ? 0 : 2), 8, "SDA1 (I2C)", "SDA.1 pin has a physical pull-up resistor")); - header.add(new HeaderPin(4, PinType.POWER, "5.0 VDC")); + header.add(new HeaderPin(4, PinType.POWER, "5.0 VDC")); header.add(new HeaderPin(5, PinType.DIGITAL_NO_PULL_DOWN, PinFunction.I2C, (type == 1 ? 1 : 3), 9, "SCL1 (I2C)", "SCL.1 pin has a physical pull-up resistor")); - header.add(new HeaderPin(6, PinType.GROUND, "Ground")); + header.add(new HeaderPin(6, PinType.GROUND, "Ground")); header.add(new HeaderPin(7, PinType.DIGITAL, PinFunction.GPCLK, 4, 7, "GPCLK0")); - header.add(new HeaderPin(8, PinType.DIGITAL, PinFunction.UART, 14, 15, "UART TxD")); - header.add(new HeaderPin(9, PinType.GROUND, "Ground")); + header.add(new HeaderPin(8, PinType.DIGITAL, PinFunction.UART, 14, 15, "UART TxD")); + header.add(new HeaderPin(9, PinType.GROUND, "Ground")); header.add(new HeaderPin(10, PinType.DIGITAL, PinFunction.UART, 15, 16, "UART RxD")); header.add(new HeaderPin(11, PinType.DIGITAL, PinFunction.SPI, 17, 0, "")); header.add(new HeaderPin(12, PinType.DIGITAL_AND_PWM, PinFunction.SPI, 18, 1, "PCM_CLK/PWM0", "Supports PWM0 [ALT5]")); @@ -80,6 +157,11 @@ static List get26PinsHeader(int type) { return header; } + /** + * Generates the 40-pin header configuration. + * + * @return a list of {@link HeaderPin} objects representing the 40-pin header. + */ static List get40PinsHeader() { List header = new ArrayList<>(); @@ -103,21 +185,33 @@ static List get40PinsHeader() { return header; } + /** + * Generates the pin configuration for the Compute Module J5 header. + *

+ * This method has not been implemented yet. The pinout configuration for the + * Compute Module J5 header can be found at: + * J5 Pinout. + *

+ * + * @return a list of {@link HeaderPin} objects representing the Compute J5 header. + */ static List getComputeJ5() { - List header = new ArrayList<>(); - - // TODO - // https://pi4j.com/1.2/pins/model-cm-rev1.html#J5_Pinout_60-pin_Header - - return header; + //TODO implement this method with the correct pin configuration + return new ArrayList<>(); } + /** + * Generates the pin configuration for the Compute Module J6 header. + *

+ * This method has not been implemented yet. The pinout configuration for the + * Compute Module J6 header can be found at: + * J6 Pinout. + *

+ * + * @return a list of {@link HeaderPin} objects representing the Compute J6 header. + */ static List getComputeJ6() { - List header = new ArrayList<>(); - - // TODO - // https://pi4j.com/1.2/pins/model-cm-rev1.html#J6_Pinout_60-pin_Header - - return header; + //TODO implement this method with the correct pin configuration + return new ArrayList<>(); } } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderVersion.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderVersion.java index be69884f..96beb662 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderVersion.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/HeaderVersion.java @@ -1,34 +1,109 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : HeaderVersion.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import java.util.ArrayList; import java.util.List; +/** + * Enum representing different header versions available on various Raspberry Pi models. + * Each header version includes a label, a description, and a list of associated header pin configurations. + */ public enum HeaderVersion { + + /** + * Header version used on the Pico microcontroller. + */ PICO("Pico", "Used on the Pico microcontroller", new ArrayList<>()), + + /** + * Header version type 1, used on the original Model B. + */ TYPE_1("Type 1", "Used on original Model B", List.of(HeaderPins.HEADER_26_TYPE_1)), + + /** + * Header version type 2, used on Model A and Model B (revision 2). + */ TYPE_2("Type 2", "Used on Model A and Model B (revision 2)", List.of(HeaderPins.HEADER_26_TYPE_2, HeaderPins.HEADER_8)), + + /** + * Header version type 3, used on various models including A+, B+, Pi Zero, and Pi5B. + */ TYPE_3("Type 3", "Used on Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B, Pi5B", List.of(HeaderPins.HEADER_40)), + + /** + * Header version used for the Compute Module series with 54 GPIO pins. + */ COMPUTE("Compute Module", "54 GPIO", List.of(HeaderPins.COMPUTE_J5, HeaderPins.COMPUTE_J6)), + + /** + * Unknown or unspecified header version. + */ UNKNOWN("Unknown", "", new ArrayList<>()); private final String label; private final String description; private final List headerPins; + /** + * Constructs a {@link HeaderVersion} enum constant. + * + * @param label the label describing the header version. + * @param description a brief description of the header version and its use. + * @param headerPins the list of {@link HeaderPins} associated with this header version. + */ HeaderVersion(String label, String description, List headerPins) { this.label = label; this.description = description; this.headerPins = headerPins; } + /** + * Retrieves the label for the header version. + * + * @return the label of the header version. + */ public String getLabel() { return label; } + /** + * Retrieves the description of the header version. + * + * @return a brief description of the header version. + */ public String getDescription() { return description; } + /** + * Retrieves the list of header pin configurations associated with the header version. + * + * @return a list of {@link HeaderPins} for the header version. + */ public List getHeaderPins() { return headerPins; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/InstructionSet.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/InstructionSet.java index f4028338..d221e672 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/InstructionSet.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/InstructionSet.java @@ -1,18 +1,76 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : InstructionSet.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Enum representing various instruction sets supported by different Raspberry Pi processors. + */ public enum InstructionSet { + + /** + * ARMv6-M instruction set, typically used in microcontroller applications. + */ ARM_V6_M("ARMv6-M"), + + /** + * ARMv6 instruction set, an early ARM architecture version used in older devices. + */ ARM_V6("ARMv6"), + + /** + * ARMv7 instruction set, commonly used in mid-range ARM processors. + */ ARM_V7("ARMv7"), + + /** + * ARMv8 instruction set, supporting 64-bit architecture and used in modern processors. + */ ARM_V8("ARMv8"), + + /** + * Unknown or unspecified instruction set. + */ UNKNOWN("Unknown"); private final String label; + /** + * Constructs an {@link InstructionSet} enum constant with a specific label. + * + * @param label the string label representing the instruction set. + */ InstructionSet(String label) { this.label = label; } + /** + * Retrieves the label for the instruction set. + * + * @return the label of the instruction set. + */ public String getLabel() { return label; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PiModel.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PiModel.java index 62775beb..4486a9c6 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PiModel.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PiModel.java @@ -1,28 +1,99 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : PiModel.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Enum representing various Raspberry Pi models, their general features, and form factors. + */ public enum PiModel { + + /** + * Compute Module: Raspberry Pi on a 200-pin DDR2-memory-like module + * designed for integration in embedded devices. + */ COMPUTE("Compute Module", "Pi on a 200-pin DDR2-memory-like module for integration in embedded devices"), + + /** + * Model A: Raspberry Pi without an Ethernet connector. + * A more cost-effective and compact model. + */ MODEL_A("Model A", "Without ethernet connector"), + + /** + * Model B: Raspberry Pi with an Ethernet connector. + * Offers more connectivity options compared to Model A. + */ MODEL_B("Model B", "With ethernet connector"), + + /** + * Pico: A microcontroller version of Raspberry Pi. + * Designed for IoT, robotics, and low-power applications. + */ PICO("Pico", "Microcontroller"), + + /** + * Zero: Smaller-sized Raspberry Pi with reduced GPIO capabilities, + * ideal for compact and lightweight applications. + */ ZERO("Zero", "Smaller size and reduced GPIO capabilities"), + + /** + * Unknown: Represents an unspecified or unsupported Raspberry Pi model. + */ UNKNOWN("Unknown", ""); private final String label; private final String description; + /** + * Constructs a {@link PiModel} enum constant with a label and description. + * + * @param label the name of the Raspberry Pi model. + * @param description a brief description of the model's features or intended use. + */ PiModel(String label, String description) { this.label = label; this.description = description; - } + /** + * Retrieves the label for the Raspberry Pi model. + * + * @return the label of the Pi model. + */ public String getLabel() { return label; } + /** + * Retrieves the description of the Raspberry Pi model. + * + * @return a brief description of the model. + */ public String getDescription() { return description; } } - diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinFunction.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinFunction.java index 0b9f64f6..2287f352 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinFunction.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinFunction.java @@ -1,26 +1,88 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : PinFunction.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + /** - * List of pin functions in a header. + * Enum representing the functions of pins on a Raspberry Pi header. + * Each pin function is associated with a label and a description explaining its purpose. */ public enum PinFunction { + + /** + * UART (Universal Asynchronous Receiver and Transmitter): + * Used for asynchronous serial communication between devices. + */ UART("Universal Asynchronous Receiver and Transmitter", "Asynchronous serial communication protocol"), + + /** + * GPCLK (General Purpose Clock): + * Provides a fixed frequency output for various clock-related applications. + */ GPCLK("General Purpose Clock", "Output a fixed frequency"), + + /** + * I2C (Inter Integrated Circuit): + * A synchronous, multi-master, multi-slave serial computer bus used for low-speed communication between components. + */ I2C("Inter Integrated Circuit", "Synchronous serial computer bus"), + + /** + * SPI (Serial Peripheral Interface): + * A four-wire serial communication protocol commonly used for short-distance device communication. + */ SPI("Serial Peripheral Interface", "Four-wire serial bus"); private final String label; private final String description; + /** + * Constructs a {@link PinFunction} enum constant with a label and description. + * + * @param label the name of the pin function. + * @param description a brief explanation of the pin function. + */ PinFunction(String label, String description) { this.label = label; this.description = description; } + /** + * Retrieves the label for the pin function. + * + * @return the label of the pin function. + */ public String getLabel() { return label; } + /** + * Retrieves the description of the pin function. + * + * @return a brief explanation of the pin function. + */ public String getDescription() { return description; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinType.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinType.java index 40211080..0c7b7494 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinType.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/PinType.java @@ -1,27 +1,99 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : PinType.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + /** - * List of pin types in a header. + * Enum representing the different types of pins on a Raspberry Pi header. + * Each pin type is associated with a label for its purpose and a color code for visualization. */ public enum PinType { + + /** + * Power Pin: + * Supplies electrical power (e.g., 3.3V or 5V) to devices or circuits. + * Represented by the color code 0x990000 (red). + */ POWER("Power", 0x990000), + + /** + * Ground Pin: + * Provides a common return path for electrical current. + * Represented by the color code 0x000000 (black). + */ GROUND("Ground", 0x000000), + + /** + * Digital Pin: + * Supports general-purpose digital input/output. + * Represented by the color code 0x009900 (green). + */ DIGITAL("Digital", 0x009900), + + /** + * Digital and PWM Pin: + * Supports general-purpose digital input/output as well as Pulse Width Modulation (PWM) for controlling devices like motors. + * Represented by the color code 0xff7f00 (orange). + */ DIGITAL_AND_PWM("Digital and PWM", 0xff7f00), + + /** + * Digital without Pulldown Pin: + * Digital pin that does not include a pull-down resistor, which may require external circuitry for proper usage. + * Represented by the color code 0x800080 (purple). + */ DIGITAL_NO_PULL_DOWN("Digital without pulldown", 0x800080); private final String label; private final int color; + /** + * Constructs a {@link PinType} enum constant with a label and a color code. + * + * @param label a descriptive name for the pin type. + * @param color a hexadecimal color code representing the pin type for visualization. + */ PinType(String label, int color) { this.label = label; this.color = color; } + /** + * Retrieves the label for the pin type. + * + * @return the label of the pin type. + */ public String getLabel() { return label; } + /** + * Retrieves the color code associated with the pin type. + * + * @return the hexadecimal color code of the pin type. + */ public int getColor() { return color; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Soc.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Soc.java index 2343a6b4..48e6adfd 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Soc.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/definition/Soc.java @@ -1,24 +1,118 @@ package com.pi4j.boardinfo.definition; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : Soc.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Enum representing various System on Chip (SoC) models used in Raspberry Pi and related hardware. + * Each SoC is associated with a specific instruction set architecture. + */ public enum Soc { + + /** + * BCM2710A1: + * SoC based on the ARMv8 instruction set architecture. + */ BCM2710A1(InstructionSet.ARM_V8), + + /** + * BCM2711: + * SoC based on the ARMv8 instruction set architecture. + */ BCM2711(InstructionSet.ARM_V8), + + /** + * BCM2711C0: + * Revision C0 of the BCM2711 SoC, based on the ARMv8 instruction set architecture. + */ BCM2711C0(InstructionSet.ARM_V8), + + /** + * BCM2712: + * SoC based on the ARMv8 instruction set architecture, used in newer Raspberry Pi models. + */ BCM2712(InstructionSet.ARM_V8), + + /** + * BCM2835: + * SoC based on the ARMv6 instruction set architecture, used in older Raspberry Pi models. + */ BCM2835(InstructionSet.ARM_V6), + + /** + * BCM2836: + * SoC based on the ARMv7 instruction set architecture. + */ BCM2836(InstructionSet.ARM_V7), + + /** + * BCM2837: + * SoC based on the ARMv8 instruction set architecture, used in Raspberry Pi 3 models. + */ BCM2837(InstructionSet.ARM_V8), + + /** + * BCM2837B0: + * Revision B0 of the BCM2837 SoC, based on the ARMv8 instruction set architecture. + */ BCM2837B0(InstructionSet.ARM_V8), + + /** + * RP2040: + * Microcontroller SoC based on the ARMv6-M instruction set architecture, used in the Raspberry Pi Pico. + */ RP2040(InstructionSet.ARM_V6_M), + + /** + * RP2350: + * Microcontroller SoC based on the ARMv6-M instruction set architecture. + */ RP2350(InstructionSet.ARM_V6_M), + + /** + * UNKNOWN: + * Placeholder for unidentified or unsupported SoCs, associated with an unknown instruction set. + */ UNKNOWN(InstructionSet.UNKNOWN); private final InstructionSet instructionSet; + /** + * Constructs a {@link Soc} enum constant with its associated instruction set architecture. + * + * @param instructionSet the {@link InstructionSet} associated with the SoC. + */ Soc(InstructionSet instructionSet) { this.instructionSet = instructionSet; } + /** + * Retrieves the instruction set architecture for this SoC. + * + * @return the {@link InstructionSet} of the SoC. + */ public InstructionSet getInstructionSet() { return instructionSet; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardInfo.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardInfo.java index 2ec8e2dc..915d626c 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardInfo.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardInfo.java @@ -1,27 +1,79 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : BoardInfo.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import com.pi4j.boardinfo.definition.BoardModel; +/** + * Represents information about a specific board, including its model, + * operating system, and Java environment details. + */ public class BoardInfo { private final BoardModel boardModel; private final OperatingSystem operatingSystem; private final JavaInfo javaInfo; + /** + * Constructs a {@link BoardInfo} instance with the specified board model, operating system, + * and Java environment information. + * + * @param boardModel the {@link BoardModel} representing the board's model. + * @param operatingSystem the {@link OperatingSystem} information for the board. + * @param javaInfo the {@link JavaInfo} information related to the board's Java environment. + */ public BoardInfo(BoardModel boardModel, OperatingSystem operatingSystem, JavaInfo javaInfo) { this.boardModel = boardModel; this.operatingSystem = operatingSystem; this.javaInfo = javaInfo; } + /** + * Gets the model of the board. + * + * @return the {@link BoardModel} of the board. + */ public BoardModel getBoardModel() { return boardModel; } + /** + * Gets the operating system running on the board. + * + * @return the {@link OperatingSystem} of the board. + */ public OperatingSystem getOperatingSystem() { return operatingSystem; } + /** + * Gets the Java environment information for the board. + * + * @return the {@link JavaInfo} related to the board. + */ public JavaInfo getJavaInfo() { return javaInfo; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardReading.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardReading.java index 74e89529..9c91abd6 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardReading.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardReading.java @@ -1,8 +1,38 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : BoardReading.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Represents the readings from a Raspberry Pi board including information + * about its code, version, temperature, uptime, voltage, and memory usage. + * Provides utility methods to parse and convert these readings. + */ public class BoardReading { private static final Logger logger = LoggerFactory.getLogger(BoardReading.class); @@ -14,40 +44,86 @@ public class BoardReading { private final String volt; private final String memory; + /** + * Constructor to initialize a {@link BoardReading} object. + * + * @param boardCode the unique code for the board. + * @param boardVersionCode the version code of the board. + * @param temperature the temperature reading of the board (in string format). + * @param uptimeInfo the uptime information for the board. + * @param volt the voltage reading of the board (in string format). + * @param memory the memory usage information for the board. + */ public BoardReading(String boardCode, String boardVersionCode, String temperature, String uptimeInfo, String volt, String memory) { - this.boardCode = boardCode; - this.boardVersionCode = boardVersionCode; - this.temperature = temperature; - this.uptimeInfo = uptimeInfo; - this.volt = volt; - this.memory = memory; + this.boardCode = boardCode; + this.boardVersionCode = boardVersionCode; + this.temperature = temperature; + this.uptimeInfo = uptimeInfo; + this.volt = volt; + this.memory = memory; } + /** + * Gets the unique code of the board. + * + * @return the board code as a string. + */ public String getBoardCode() { return boardCode; } + /** + * Gets the version code of the board. + * + * @return the version code of the board as a string. + */ public String getBoardVersionCode() { return boardVersionCode; } + /** + * Gets the temperature reading of the board in string format. + * + * @return the temperature reading as a string (e.g., "temp=45.0'C"). + */ public String getTemperature() { return temperature; } + /** + * Gets the uptime information of the board. + * + * @return the uptime information as a string. + */ public String getUptimeInfo() { return uptimeInfo; } + /** + * Gets the voltage reading of the board in string format. + * + * @return the voltage as a string (e.g., "volt=5.1V"). + */ public String getVolt() { return volt; } + /** + * Gets the memory usage information of the board. + * + * @return the memory usage as a string. + */ public String getMemory() { return memory; } + /** + * Converts the temperature reading to Celsius. The expected input format is: + * "temp=XX.X'C" or "temp=XX.X°C". + * + * @return the temperature in Celsius as a double, or 0 if the conversion fails. + */ public double getTemperatureInCelsius() { if (temperature.contains("temp=")) { try { @@ -62,10 +138,23 @@ public double getTemperatureInCelsius() { return 0; } + /** + * Converts the temperature reading to Fahrenheit. + * This method uses the Celsius temperature and applies the conversion formula: + * (Celsius * 1.8) + 32. + * + * @return the temperature in Fahrenheit. + */ public double getTemperatureInFahrenheit() { return (getTemperatureInCelsius() * 1.8) + 32; } + /** + * Converts the voltage reading to a numeric value. + * The expected input format is "volt=XX.XV". + * + * @return the voltage value as a double, or 0 if the conversion fails. + */ public double getVoltValue() { if (volt.contains("volt=")) { try { diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/HeaderPin.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/HeaderPin.java index 34645a71..cc1c5bd8 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/HeaderPin.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/HeaderPin.java @@ -1,28 +1,85 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : HeaderPin.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + import com.pi4j.boardinfo.definition.PinFunction; import com.pi4j.boardinfo.definition.PinType; /** - * Describes a pin in the header. + * Represents a pin on a Raspberry Pi header. + * Contains information about the pin's number, type, function, + * as well as its BCM and WiringPi numbers, name, and any remarks. */ public class HeaderPin { - private final int pinNumber; - private final PinType pinType; - private final PinFunction pinFunction; - private final Integer bcmNumber; - private final Integer wiringPiNumber; - private final String name; - private final String remark; + private final int pinNumber; // The physical pin number on the header + private final PinType pinType; // The type of pin (Power, Ground, Digital, etc.) + private final PinFunction pinFunction; // The function of the pin (e.g., UART, I2C, SPI) + private final Integer bcmNumber; // The BCM GPIO number, if applicable + private final Integer wiringPiNumber; // The WiringPi number, if applicable + private final String name; // The name of the pin (e.g., "GPIO17") + private final String remark; // Any additional remarks or information about the pin + + /** + * Constructs a HeaderPin with only the pin number, pin type, and name. + * + * @param pinNumber The physical pin number. + * @param pinType The type of pin (e.g., Power, Ground, Digital). + * @param name The name of the pin (e.g., "GPIO17"). + */ public HeaderPin(int pinNumber, PinType pinType, String name) { this(pinNumber, pinType, null, null, null, name, ""); } + /** + * Constructs a HeaderPin with the pin number, pin type, pin function, + * BCM number, WiringPi number, and name. + * + * @param pinNumber The physical pin number. + * @param pinType The type of pin (e.g., Power, Ground, Digital). + * @param pinFunction The function of the pin (e.g., UART, I2C). + * @param bcmNumber The BCM GPIO number, if applicable. + * @param wiringPiNumber The WiringPi number, if applicable. + * @param name The name of the pin (e.g., "GPIO17"). + */ public HeaderPin(int pinNumber, PinType pinType, PinFunction pinFunction, Integer bcmNumber, Integer wiringPiNumber, String name) { this(pinNumber, pinType, pinFunction, bcmNumber, wiringPiNumber, name, ""); } + /** + * Constructs a HeaderPin with all the available information, including remarks. + * + * @param pinNumber The physical pin number. + * @param pinType The type of pin (e.g., Power, Ground, Digital). + * @param pinFunction The function of the pin (e.g., UART, I2C). + * @param bcmNumber The BCM GPIO number, if applicable. + * @param wiringPiNumber The WiringPi number, if applicable. + * @param name The name of the pin (e.g., "GPIO17"). + * @param remark Any additional remarks about the pin. + */ public HeaderPin(int pinNumber, PinType pinType, PinFunction pinFunction, Integer bcmNumber, Integer wiringPiNumber, String name, String remark) { this.pinNumber = pinNumber; this.pinType = pinType; @@ -33,26 +90,65 @@ public HeaderPin(int pinNumber, PinType pinType, PinFunction pinFunction, Intege this.remark = remark; } + /** + * Gets the physical pin number on the header. + * + * @return The pin number as an integer. + */ public int getPinNumber() { return pinNumber; } + /** + * Gets the type of pin (e.g., Power, Ground, Digital). + * + * @return The PinType for this pin. + */ public PinType getPinType() { return pinType; } - public PinFunction getPinFunction() { return pinFunction; } + /** + * Gets the function of the pin (e.g., UART, I2C, SPI). + * + * @return The PinFunction of the pin. + */ + public PinFunction getPinFunction() { + return pinFunction; + } - public Integer getBcmNumber() { return bcmNumber; } + /** + * Gets the BCM GPIO number associated with this pin, if available. + * + * @return The BCM GPIO number as an Integer, or null if not available. + */ + public Integer getBcmNumber() { + return bcmNumber; + } + /** + * Gets the WiringPi number associated with this pin, if available. + * + * @return The WiringPi number as an Integer, or null if not available. + */ public Integer getWiringPiNumber() { return wiringPiNumber; } + /** + * Gets the name of the pin (e.g., "GPIO17"). + * + * @return The name of the pin as a String. + */ public String getName() { return name; } + /** + * Gets any additional remarks or information about the pin. + * + * @return Any remarks as a String, or an empty string if no remarks exist. + */ public String getRemark() { return remark; } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JavaInfo.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JavaInfo.java index b04a7e91..cbe63fdd 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JavaInfo.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JavaInfo.java @@ -1,12 +1,49 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : JavaInfo.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Represents information about the Java runtime environment. + * This includes the version, runtime, vendor, and vendor version of the Java environment. + */ public class JavaInfo { - private final String version; - private final String runtime; - private final String vendor; - private final String vendorVersion; + private final String version; // Java version (e.g., "11.0.10") + private final String runtime; // The runtime environment (e.g., "Zulu OpenJDK 11.0.10") + private final String vendor; // The vendor of the Java runtime (e.g., "Azul Systems") + private final String vendorVersion; // The vendor's version of the Java runtime (e.g., "11.0.10+10") + /** + * Constructs a JavaInfo object with the specified details about the Java runtime. + * + * @param version The version of the Java runtime (e.g., "11.0.10"). + * @param runtime The runtime environment (e.g., "Zulu OpenJDK 11.0.10"). + * @param vendor The vendor of the Java runtime (e.g., "Azul Systems"). + * @param vendorVersion The vendor's version of the Java runtime (e.g., "11.0.10+10"). + */ public JavaInfo(String version, String runtime, String vendor, String vendorVersion) { this.version = version; this.runtime = runtime; @@ -14,22 +51,47 @@ public JavaInfo(String version, String runtime, String vendor, String vendorVers this.vendorVersion = vendorVersion; } + /** + * Gets the version of the Java runtime. + * + * @return The version of the Java runtime as a String. + */ public String getVersion() { return version; } + /** + * Gets the runtime environment of Java. + * + * @return The runtime environment as a String (e.g., "Zulu OpenJDK 11.0.10"). + */ public String getRuntime() { return runtime; } + /** + * Gets the vendor of the Java runtime. + * + * @return The vendor of the Java runtime (e.g., "Azul Systems"). + */ public String getVendor() { return vendor; } + /** + * Gets the version of the Java runtime as provided by the vendor. + * + * @return The vendor version of the Java runtime (e.g., "11.0.10+10"). + */ public String getVendorVersion() { return vendorVersion; } + /** + * Returns a string representation of the Java runtime information. + * + * @return A string summarizing the version, runtime, vendor, and vendor version. + */ @Override public String toString() { return "Version: " + version diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JvmMemory.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JvmMemory.java index f19b91b9..84630b8a 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JvmMemory.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/JvmMemory.java @@ -1,50 +1,127 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : JvmMemory.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Provides memory information about the Java Virtual Machine (JVM). + * This class allows you to retrieve details such as total memory, free memory, + * used memory, and maximum available memory, as well as their values in megabytes. + */ public class JvmMemory { - private static final double mb = 1024.0 * 1024.0; + // Constant to convert bytes to megabytes + private static final double MB = 1024.0 * 1024.0; - private final long total; - private final long free; - private final long used; - private final long max; + // Instance variables to store memory values + private final long total; // Total memory in bytes + private final long free; // Free memory in bytes + private final long used; // Used memory in bytes + private final long max; // Maximum memory in bytes + /** + * Constructor that initializes memory details based on the JVM runtime. + * + * @param runtime The runtime instance used to retrieve memory information. + */ public JvmMemory(Runtime runtime) { - total = runtime.totalMemory(); - free = runtime.freeMemory(); - used = runtime.totalMemory() - runtime.freeMemory(); - max = runtime.maxMemory(); + total = runtime.totalMemory(); // Total memory allocated to the JVM + free = runtime.freeMemory(); // Free memory available for objects in the JVM + used = total - free; // Used memory is the difference between total and free + max = runtime.maxMemory(); // Maximum memory that the JVM can use } + /** + * Gets the total memory allocated to the JVM in bytes. + * + * @return Total memory in bytes. + */ public long getTotal() { return total; } + /** + * Gets the free memory available in the JVM in bytes. + * + * @return Free memory in bytes. + */ public long getFree() { return free; } + /** + * Gets the used memory in the JVM in bytes. + * + * @return Used memory in bytes. + */ public long getUsed() { return used; } + /** + * Gets the maximum memory that the JVM can use in bytes. + * + * @return Maximum memory in bytes. + */ public long getMax() { return max; } + /** + * Gets the total memory in megabytes. + * + * @return Total memory in MB. + */ public double getTotalInMb() { - return total / mb; + return total / MB; } + /** + * Gets the free memory in megabytes. + * + * @return Free memory in MB. + */ public double getFreeInMb() { - return free / mb; + return free / MB; } + /** + * Gets the used memory in megabytes. + * + * @return Used memory in MB. + */ public double getUsedInMb() { - return used / mb; + return used / MB; } + /** + * Gets the maximum memory the JVM can use in megabytes. + * + * @return Maximum memory in MB. + */ public double getMaxInMb() { - return max / mb; + return max / MB; } } diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/OperatingSystem.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/OperatingSystem.java index 1489168e..5eba0f10 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/model/OperatingSystem.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/model/OperatingSystem.java @@ -1,29 +1,85 @@ package com.pi4j.boardinfo.model; +/*- + * #%L + * ********************************************************************** + * ORGANIZATION : Pi4J + * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) + * FILENAME : OperatingSystem.java + * + * This file is part of the Pi4J project. More information about + * this project can be found here: https://pi4j.com/ + * ********************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +/** + * Represents information about an operating system. + * This includes the name, version, and architecture of the operating system. + */ public class OperatingSystem { - private final String name; - private final String version; - private final String architecture; + private final String name; // The name of the operating system (e.g., "Linux") + private final String version; // The version of the operating system (e.g., "Ubuntu 20.04") + private final String architecture; // The architecture of the operating system (e.g., "x86_64") + /** + * Constructs an OperatingSystem object with the specified details. + * + * @param name The name of the operating system (e.g., "Linux"). + * @param version The version of the operating system (e.g., "Ubuntu 20.04"). + * @param architecture The architecture of the operating system (e.g., "x86_64"). + */ public OperatingSystem(String name, String version, String architecture) { this.name = name; this.version = version; this.architecture = architecture; } + /** + * Gets the name of the operating system. + * + * @return The name of the operating system as a String (e.g., "Linux"). + */ public String getName() { return name; } + /** + * Gets the version of the operating system. + * + * @return The version of the operating system as a String (e.g., "Ubuntu 20.04"). + */ public String getVersion() { return version; } + /** + * Gets the architecture of the operating system. + * + * @return The architecture of the operating system as a String (e.g., "x86_64"). + */ public String getArchitecture() { return architecture; } + /** + * Returns a string representation of the operating system information. + * + * @return A string summarizing the name, version, and architecture of the operating system. + */ @Override public String toString() { return "Name: " + name @@ -31,3 +87,4 @@ public String toString() { + ", architecture: " + architecture; } } + diff --git a/pi4j-core/src/main/java/com/pi4j/boardinfo/util/Command.java b/pi4j-core/src/main/java/com/pi4j/boardinfo/util/Command.java index a7e5a06a..ab28e1eb 100644 --- a/pi4j-core/src/main/java/com/pi4j/boardinfo/util/Command.java +++ b/pi4j-core/src/main/java/com/pi4j/boardinfo/util/Command.java @@ -5,7 +5,7 @@ * ********************************************************************** * ORGANIZATION : Pi4J * PROJECT : Pi4J :: LIBRARY :: Java Library (CORE) - * FILENAME : CommandProperties.java + * FILENAME : Command.java * * This file is part of the Pi4J project. More information about * this project can be found here: https://pi4j.com/ diff --git a/pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java b/pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java index 995dd9d3..898a2a50 100644 --- a/pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java +++ b/pi4j-core/src/test/java/com/pi4j/boardinfo/definition/BoardModelTest.java @@ -1,5 +1,8 @@ package com.pi4j.boardinfo.definition; +import com.pi4j.boardinfo.model.BoardInfo; +import com.pi4j.boardinfo.model.JavaInfo; +import com.pi4j.boardinfo.model.OperatingSystem; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -43,4 +46,30 @@ void boardCodesMustBeUnique() { }); } } + + @Test + void testBoardInfo() { + var model = BoardModel.MODEL_4_B; + var boardInfo = new BoardInfo( + model, + new OperatingSystem( + "Linux", + "5.4.0", + "arm64"), + new JavaInfo( + "11.0.8", + "OpenJDK", + "Oracle", + "11.0.8" + ) + ); + + assertAll( + () -> assertEquals("Linux", boardInfo.getOperatingSystem().getName()), + () -> assertEquals("5.4.0", boardInfo.getOperatingSystem().getVersion()), + () -> assertEquals("arm64", boardInfo.getOperatingSystem().getArchitecture()), + () -> assertEquals("11.0.8", boardInfo.getJavaInfo().getVersion()), + () -> assertEquals("OpenJDK", boardInfo.getJavaInfo().getRuntime()) + ); + } }