-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frank Delporte
committed
Apr 15, 2024
1 parent
dc13031
commit 48bf3e0
Showing
6 changed files
with
198 additions
and
11 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
pi4j-core/src/main/java/com/pi4j/boardinfo/model/BoardReading.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.pi4j.boardinfo.model; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class BoardReading { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(BoardReading.class); | ||
|
||
private final String boardCode; | ||
private final String boardVersionCode; | ||
private final String temperature; | ||
private final String uptimeInfo; | ||
private final String volt; | ||
private final String memory; | ||
|
||
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; | ||
} | ||
|
||
public String getBoardCode() { | ||
return boardCode; | ||
} | ||
|
||
public String getBoardVersionCode() { | ||
return boardVersionCode; | ||
} | ||
|
||
public String getTemperature() { | ||
return temperature; | ||
} | ||
|
||
public String getUptimeInfo() { | ||
return uptimeInfo; | ||
} | ||
|
||
public String getVolt() { | ||
return volt; | ||
} | ||
|
||
public String getMemory() { | ||
return memory; | ||
} | ||
|
||
public double getTemperatureInCelsius() { | ||
if (temperature.contains("temp=")) { | ||
try { | ||
return Double.parseDouble(temperature | ||
.replace("temp=", "") | ||
.replace("'C", "") | ||
.replace("°C", "")); | ||
} catch (Exception e) { | ||
logger.error("Can't convert temperature value: {}", e.getMessage()); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
public double getTemperatureInFahrenheit() { | ||
return (getTemperatureInCelsius() * 1.8) + 32; | ||
} | ||
|
||
public double getVoltValue() { | ||
if (volt.contains("volt=")) { | ||
try { | ||
return Double.parseDouble(volt | ||
.replace("volt=", "") | ||
.replace("V", "")); | ||
} catch (Exception e) { | ||
logger.error("Can't convert volt value: {}", e.getMessage()); | ||
} | ||
} | ||
return 0; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
pi4j-core/src/main/java/com/pi4j/boardinfo/model/JvmMemory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.pi4j.boardinfo.model; | ||
|
||
public class JvmMemory { | ||
|
||
private static double mb = 1024.0 * 1024.0; | ||
|
||
private final long total; | ||
private final long free; | ||
private final long used; | ||
private final long max; | ||
|
||
public JvmMemory(Runtime runtime) { | ||
total = runtime.totalMemory(); | ||
free = runtime.freeMemory(); | ||
used = runtime.totalMemory() - runtime.freeMemory(); | ||
max = runtime.maxMemory(); | ||
} | ||
|
||
public long getTotal() { | ||
return total; | ||
} | ||
|
||
public long getFree() { | ||
return free; | ||
} | ||
|
||
public long getUsed() { | ||
return used; | ||
} | ||
|
||
public long getMax() { | ||
return max; | ||
} | ||
|
||
public double getTotalInMb() { | ||
return total / mb; | ||
} | ||
|
||
public double getFreeInMb() { | ||
return free / mb; | ||
} | ||
|
||
public double getUsedInMb() { | ||
return used / mb; | ||
} | ||
|
||
public double getMaxInMb() { | ||
return max / mb; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters