diff --git a/.gitignore b/.gitignore index 1017a23..5f4535c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /vite.generated.ts /SERVER_INSTALL.md /src/main/dev-bundle/ +/src/main/bundles/ diff --git a/pom.xml b/pom.xml index 1a6564f..56f72ee 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.0 + 3.2.4 @@ -20,9 +20,9 @@ 17 - 0.3.0 - 2.1.0 - 24.2.4 + 2.5.1-SNAPSHOT + 2.5.0 + 24.3.9 @@ -96,8 +96,8 @@ com.pi4j - pi4j-board-info - ${pi4j.boardinfo.version} + pi4j-core + ${pi4j.version} @@ -236,10 +236,15 @@ - vaadin-prereleases - - https://maven.vaadin.com/vaadin-prereleases/ - + oss-snapshots-repo + Sonatype OSS Maven Repository + https://oss.sonatype.org/content/groups/public + + false + + + true + diff --git a/src/main/java/com/pi4j/boardinfoservice/controller/RaspberryPiInfoController.java b/src/main/java/com/pi4j/boardinfoservice/controller/RaspberryPiInfoController.java index c7846f4..dd41d1c 100644 --- a/src/main/java/com/pi4j/boardinfoservice/controller/RaspberryPiInfoController.java +++ b/src/main/java/com/pi4j/boardinfoservice/controller/RaspberryPiInfoController.java @@ -33,17 +33,4 @@ public ResponseEntity getBoardByName(@PathVariable String name) { } return ResponseEntity.notFound().build(); } - - /* - // Not very useful, this returns a set of Vaadin HTML components that don't render as a table - @GetMapping("/header/{name}/html") - public ResponseEntity getHeaderView(@PathVariable String name) { - var header = raspberryPiInfoService.getRaspberryPiHeaderByName(name); - if (header.isPresent()) { - var view = new HeaderPinView(header.get()); - return ResponseEntity.ok().body(view.getElement().getOuterHTML()); - } - return ResponseEntity.notFound().build(); - } - */ } diff --git a/src/main/java/com/pi4j/boardinfoservice/controller/ServiceInfoController.java b/src/main/java/com/pi4j/boardinfoservice/controller/ServiceInfoController.java index 880a70e..f19a525 100644 --- a/src/main/java/com/pi4j/boardinfoservice/controller/ServiceInfoController.java +++ b/src/main/java/com/pi4j/boardinfoservice/controller/ServiceInfoController.java @@ -1,13 +1,13 @@ package com.pi4j.boardinfoservice.controller; -import com.pi4j.boardinfo.model.DetectedBoard; +import com.pi4j.boardinfo.model.BoardInfo; +import com.pi4j.boardinfo.model.BoardReading; +import com.pi4j.boardinfo.model.JvmMemory; import com.pi4j.boardinfoservice.service.SystemInfoService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Map; - @RestController @RequestMapping("/api/service") public class ServiceInfoController { @@ -19,17 +19,17 @@ public ServiceInfoController(SystemInfoService systemInfoService) { } @GetMapping("/board") - public DetectedBoard getDetectedBoard() { + public BoardInfo getDetectedBoard() { return systemInfoService.getDetectedBoard(); } @GetMapping("/memory") - public Map getMemory() { + public JvmMemory getMemory() { return systemInfoService.getJvmMemory(); } @GetMapping("/actual") - public Map getBoardReadings() { - return systemInfoService.getBoardReadings(); + public BoardReading getBoardReadings() { + return systemInfoService.getBoardReading(); } } diff --git a/src/main/java/com/pi4j/boardinfoservice/service/SystemInfoService.java b/src/main/java/com/pi4j/boardinfoservice/service/SystemInfoService.java index 8925191..68428a0 100644 --- a/src/main/java/com/pi4j/boardinfoservice/service/SystemInfoService.java +++ b/src/main/java/com/pi4j/boardinfoservice/service/SystemInfoService.java @@ -1,63 +1,29 @@ package com.pi4j.boardinfoservice.service; -import com.pi4j.boardinfo.model.DetectedBoard; -import com.pi4j.boardinfo.util.BoardModelDetection; -import com.pi4j.boardinfoservice.util.ExecUtil; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.pi4j.boardinfo.model.BoardInfo; +import com.pi4j.boardinfo.model.BoardReading; +import com.pi4j.boardinfo.model.JvmMemory; +import com.pi4j.boardinfo.util.BoardInfoHelper; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.Map; - @Service public class SystemInfoService { - private final Logger logger = LogManager.getLogger(SystemInfoService.class); - private final DetectedBoard detectedBoard; + private final BoardInfo boardInfo; public SystemInfoService() { - detectedBoard = BoardModelDetection.getDetectedBoard(); - } - - public DetectedBoard getDetectedBoard() { - return detectedBoard; + boardInfo = BoardInfoHelper.current(); } - public Map getJvmMemory() { - Map memory = new HashMap<>(); - - int mb = 1024 * 1024; - Runtime instance = Runtime.getRuntime(); - memory.put("total_mb", (instance.totalMemory() / mb)); - memory.put("free_mb", (instance.freeMemory() / mb)); - memory.put("used_mb", ((instance.totalMemory() - instance.freeMemory()) / mb)); - memory.put("max_mb", (instance.maxMemory() / mb)); - - return memory; + public BoardInfo getDetectedBoard() { + return boardInfo; } - public Map getBoardReadings() { - Map boardVersion = new HashMap<>(); - boardVersion.put("board", getCommandOutput("cat /proc/device-tree/model")); - // https://raspberry-projects.com/pi/command-line/detect-rpi-hardware-version - boardVersion.put("boardVersionCode", getCommandOutput("cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}'")); - // https://linuxhint.com/commands-for-hardware-information-raspberry-pi/ - boardVersion.put("temp", getCommandOutput("vcgencmd measure_temp")); - boardVersion.put("uptimeInfo", getCommandOutput("uptime")); - // https://linuxhint.com/find-hardware-information-raspberry-pi/ - boardVersion.put("volt", getCommandOutput("vcgencmd measure_volts")); - // https://www.baeldung.com/linux/total-physical-memory - boardVersion.put("memory", getCommandOutput("cat /proc/meminfo | head -n 1")); - return boardVersion; + public JvmMemory getJvmMemory() { + return BoardInfoHelper.getJvmMemory(); } - private String getCommandOutput(String command) { - ExecUtil execUtil = new ExecUtil(command); - if (!execUtil.isFinished() || !execUtil.getErrorMessage().isEmpty()) { - logger.error("Could not execute '{}': {}", command, execUtil.getErrorMessage()); - return ""; - } - return execUtil.getOutputMessage(); + public BoardReading getBoardReading() { + return BoardInfoHelper.getBoardReading(); } } diff --git a/src/main/java/com/pi4j/boardinfoservice/views/BoardInfoView.java b/src/main/java/com/pi4j/boardinfoservice/views/BoardInfoView.java index 0640bb7..aff2173 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/BoardInfoView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/BoardInfoView.java @@ -44,7 +44,7 @@ public BoardInfoView() { listBox.setMinWidth(250, Unit.PIXELS); listBox.setHeightFull(); listBox.setRenderer(new ComponentRenderer<>(board -> { - var lbl = new Label(board.getLabel()); + var lbl = new Span(board.getLabel()); lbl.setWidthFull(); return lbl; })); @@ -129,9 +129,9 @@ private void showBoard(BoardModel boardModel) { } private HorizontalLayout getLabelValue(String label, String value) { - var lbl = new Label(label); + var lbl = new Span(label); lbl.setWidth(250, Unit.PIXELS); - var labelValueHolder = new HorizontalLayout(lbl, new Label(value)); + var labelValueHolder = new HorizontalLayout(lbl, new Span(value)); labelValueHolder.setMargin(false); labelValueHolder.setPadding(false); return labelValueHolder; diff --git a/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java b/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java index 67a0a5d..bec5537 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java @@ -3,6 +3,7 @@ import com.pi4j.boardinfoservice.service.SystemInfoService; import com.vaadin.flow.component.AttachEvent; import com.vaadin.flow.component.UI; +import com.vaadin.flow.component.grid.ColumnTextAlign; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.router.PageTitle; @@ -11,7 +12,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; @PageTitle("System Information") @Route(value = "system-information", layout = BaseLayout.class) @@ -26,9 +26,15 @@ public SystemInfoView(@Autowired SystemInfoService systemInfoService) { setSpacing(false); Grid grid = new Grid<>(InfoLine.class, false); - grid.addColumn(InfoLine::type).setHeader("Type"); - grid.addColumn(InfoLine::label).setHeader("Label"); - grid.addColumn(InfoLine::info).setHeader("Info"); + grid.addColumn(InfoLine::type) + .setHeader("Type") + .setTextAlign(ColumnTextAlign.START); + grid.addColumn(InfoLine::label) + .setHeader("Label") + .setTextAlign(ColumnTextAlign.START); + grid.addColumn(InfoLine::info) + .setHeader("Info") + .setTextAlign(ColumnTextAlign.START); grid.setItems(infoList); add(grid); @@ -41,12 +47,6 @@ public SystemInfoView(@Autowired SystemInfoService systemInfoService) { @Override public void onAttach(AttachEvent event) { UI.getCurrent().access(() -> { - systemInfoService.getBoardReadings().entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .forEach(e -> infoList.add(new InfoLine("Board readings", e.getKey(), e.getValue()))); - systemInfoService.getJvmMemory().entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .forEach(e -> infoList.add(new InfoLine("JVM Memory", e.getKey(), e.getValue()))); var board = systemInfoService.getDetectedBoard(); infoList.add(new InfoLine("Board", "Name", board.getBoardModel().getName())); infoList.add(new InfoLine("Board", "Type", board.getBoardModel().getBoardType())); @@ -58,6 +58,23 @@ public void onAttach(AttachEvent event) { infoList.add(new InfoLine("Java", "Runtime", board.getJavaInfo().getRuntime())); infoList.add(new InfoLine("Java", "Vendor", board.getJavaInfo().getVendor())); infoList.add(new InfoLine("Java", "Vendor Version", board.getJavaInfo().getVendorVersion())); + + var memory = systemInfoService.getJvmMemory(); + infoList.add(new InfoLine("JVM Memory", "Free (MB)", memory.getFreeInMb())); + infoList.add(new InfoLine("JVM Memory", "Max (MB)", memory.getMaxInMb())); + infoList.add(new InfoLine("JVM Memory", "Total (MB)", memory.getTotalInMb())); + infoList.add(new InfoLine("JVM Memory", "Used (MB)", memory.getUsedInMb())); + + var reading = systemInfoService.getBoardReading(); + infoList.add(new InfoLine("Board reading", "Board code", reading.getBoardCode())); + infoList.add(new InfoLine("Board reading", "Board version code", reading.getBoardVersionCode())); + infoList.add(new InfoLine("Board reading", "Uptime", reading.getUptimeInfo())); + infoList.add(new InfoLine("Board reading", "Memory", reading.getMemory())); + infoList.add(new InfoLine("Board reading", "Temperature", reading.getTemperature())); + infoList.add(new InfoLine("Board reading", "Temperature (°C)", reading.getTemperatureInCelsius())); + infoList.add(new InfoLine("Board reading", "Temperature (°F)", reading.getTemperatureInFahrenheit())); + infoList.add(new InfoLine("Board reading", "Volt", reading.getVolt())); + infoList.add(new InfoLine("Board reading", "Volt (value)", reading.getVoltValue())); }); } diff --git a/src/main/java/com/pi4j/boardinfoservice/views/header/HeaderPinView.java b/src/main/java/com/pi4j/boardinfoservice/views/header/HeaderPinView.java index 6f67270..fefca8e 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/header/HeaderPinView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/header/HeaderPinView.java @@ -1,7 +1,7 @@ package com.pi4j.boardinfoservice.views.header; import com.pi4j.boardinfo.definition.HeaderPins; -import com.pi4j.boardinfo.pin.HeaderPin; +import com.pi4j.boardinfo.model.HeaderPin; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; @@ -18,7 +18,6 @@ public class HeaderPinView extends VerticalLayout { * @param headerPins {@link HeaderPins} to be visualized. */ public HeaderPinView(HeaderPins headerPins) { - //this.spacing(25); var rows = new HorizontalLayout(); rows.setPadding(false); rows.setMargin(false); diff --git a/src/main/java/com/pi4j/boardinfoservice/views/header/PinTypeView.java b/src/main/java/com/pi4j/boardinfoservice/views/header/PinTypeView.java index a9253c5..aaafea2 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/header/PinTypeView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/header/PinTypeView.java @@ -3,7 +3,7 @@ import com.pi4j.boardinfo.definition.PinType; import com.pi4j.boardinfoservice.util.Converter; import com.vaadin.flow.component.Unit; -import com.vaadin.flow.component.html.Label; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; @@ -30,7 +30,7 @@ class PinTypeView extends HorizontalLayout { color.getStyle().set("background-color", Converter.intToHexColor(pinType.getColor())); this.add(color); - var name = new Label(pinType.getLabel()); + var name = new Span(pinType.getLabel()); name.getStyle().set("font", "18px Tahoma") .set("font-weight", "bold"); this.add(name); diff --git a/src/main/java/com/pi4j/boardinfoservice/views/header/PinView.java b/src/main/java/com/pi4j/boardinfoservice/views/header/PinView.java index 0ba255b..e7b0c36 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/header/PinView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/header/PinView.java @@ -1,9 +1,9 @@ package com.pi4j.boardinfoservice.views.header; -import com.pi4j.boardinfo.pin.HeaderPin; +import com.pi4j.boardinfo.model.HeaderPin; import com.pi4j.boardinfoservice.util.Converter; import com.vaadin.flow.component.Unit; -import com.vaadin.flow.component.html.Label; +import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.orderedlayout.HorizontalLayout; import com.vaadin.flow.component.orderedlayout.VerticalLayout; @@ -33,13 +33,13 @@ class PinView extends HorizontalLayout { bcmHolder.setMargin(false); bcmHolder.setSpacing(false); - var bcmLabel = new Label(); + var bcmLabel = new Span(); bcmLabel.setWidth(20, Unit.PIXELS); bcmLabel.getStyle().set("font", "9px Tahoma") .set("text-align", "center"); bcmHolder.add(bcmLabel); - var bcmNumber = new Label(); + var bcmNumber = new Span(); bcmNumber.setWidth(20, Unit.PIXELS); bcmNumber.getStyle().set("font", "16px Tahoma") .set("text-align", "center"); @@ -56,13 +56,13 @@ class PinView extends HorizontalLayout { wiringHolder.setMargin(false); wiringHolder.setSpacing(false); - var wiringPiLabel = new Label(); + var wiringPiLabel = new Span(); wiringPiLabel.setWidth(20, Unit.PIXELS); wiringPiLabel.getStyle().set("font", "9px Tahoma") .set("text-align", "center"); wiringHolder.add(wiringPiLabel); - var wiringPiNumber = new Label(); + var wiringPiNumber = new Span(); wiringPiNumber.setWidth(20, Unit.PIXELS); wiringPiNumber.getStyle().set("font", "16px Tahoma") .set("text-align", "center"); @@ -74,12 +74,9 @@ class PinView extends HorizontalLayout { } // Name and info - var name = new Label(pin.getName()); + var name = new Span(pin.getName()); name.getStyle().set("font", "12px Tahoma") .set("text-align", "center"); - /*if (pin.getRemark() != null) { - name.setTooltipText(pin.getRemark()); - }*/ name.setMinWidth(180, Unit.PIXELS); name.setMaxWidth(180, Unit.PIXELS); @@ -89,14 +86,14 @@ class PinView extends HorizontalLayout { pinNumberHolder.setMargin(false); pinNumberHolder.setSpacing(false); - var pinNumberLabel = new Label(); + var pinNumberLabel = new Span(); pinNumberLabel.setWidth(20, Unit.PIXELS); pinNumberLabel.getStyle().set("font", "9px Tahoma") .set("text-align", "center"); pinNumberLabel.setText("PIN"); pinNumberHolder.add(pinNumberLabel); - var pinNumber = new Label(); + var pinNumber = new Span(); pinNumber.setWidth(20, Unit.PIXELS); pinNumber.getStyle().set("font", "16px Tahoma") .set("text-align", "center");