Skip to content

Commit 9f03375

Browse files
committed
expose NGIO getStatus method to LabQuest class
besides getting the status of the device this should be an efficient way to see if the device is attached. [#56591614]
1 parent bf8c86b commit 9f03375

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

labquest-jna/src/main/java/org/concord/sensor/labquest/jna/LabQuest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public void open(String deviceName, Pointer hLibrary)
2020

2121
public void acquireExclusiveOwnership() throws LabQuestException;
2222

23+
public LabQuestStatus getStatus() throws LabQuestException;
24+
2325
public String getSensorName(byte channel) throws LabQuestException;
2426

2527
public int getSensorId(byte channel) throws LabQuestException;

labquest-jna/src/main/java/org/concord/sensor/labquest/jna/LabQuestImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ public void acquireExclusiveOwnership() throws LabQuestException
9292
}
9393
}
9494

95+
public LabQuestStatus getStatus() throws LabQuestException
96+
{
97+
LabQuestStatus status = new LabQuestStatus();
98+
try{
99+
sendCmdAndGetResponse(NGIOSourceCmds.CMD_ID_GET_STATUS, null,
100+
status);
101+
} catch(NGIOException e) {
102+
throw new LabQuestException(e);
103+
}
104+
return status;
105+
}
95106

96107
/**
97108
* @see org.concord.sensor.labquest.jna.LabQuest#getSensorName()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.concord.sensor.labquest.jna;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
public class LabQuestStatus extends NGIOStructure {
7+
public byte status; //See NGIO_MASK_STATUS_*.
8+
public byte minorVersionMasterCPU; //Binary coded decimal
9+
public byte majorVersionMasterCPU; //Binary coded decimal
10+
public byte minorVersionSlaveCPU; //Binary coded decimal - updated only by Skip and Cyclops, not by Jonah
11+
public byte majorVersionSlaveCPU; //Binary coded decimal - updated only by Skip and Cyclops, not by Jonah
12+
13+
@Override
14+
protected List<String> getFieldOrder() {
15+
return Arrays.asList(new String[] {
16+
"status",
17+
"minorVersionMasterCPU",
18+
"majorVersionMasterCPU",
19+
"minorVersionSlaveCPU",
20+
"majorVersionSlaveCPU"
21+
});
22+
}
23+
24+
public String inspect() {
25+
return "status: " + status +
26+
", masterCPUVersion: " + majorVersionMasterCPU + "." + minorVersionMasterCPU +
27+
", slaveCPUVersion: " + majorVersionSlaveCPU + "." + minorVersionSlaveCPU;
28+
}
29+
30+
}

labquest-jna/src/main/java/org/concord/sensor/labquest/jna/NGIOLibrary.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ int device_IsRemoteCollectionActive(Pointer hDevice,
110110
int device_SendCmdAndGetResponse(Pointer hDevice, byte cmd, Structure pParams,
111111
int nParamBytes, Pointer pRespBuf, IntByReference pnRespBytes, int timeoutMs);
112112

113+
int device_GetLastCmdResponseStatus(Pointer hDevice,
114+
ByteByReference lastCmd, ByteByReference lastCmdStatus,
115+
ByteByReference lastCmdWithErrorRespSentOvertheWire,
116+
ByteByReference lastErrorSentOvertheWire);
117+
113118
// untested
114119
// need to possibly add in the NGIO_PTR structure for pParams
115120
int device_SendCmd(Pointer hDevice, byte cmd, Pointer pParms, int nParamBytes,

labquest-jna/src/test/java/org/concord/sensor/labquest/jna/LabQuestJNATest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public void run() {
8585
* @throws IOException
8686
*/
8787
public static void test() throws LabQuestException {
88+
LabQuestStatus status = labQuest.getStatus();
89+
System.out.println("labQuest status: " + status.inspect());
8890
boolean remoteCollectionActive = false;
8991
remoteCollectionActive = labQuest.isRemoteCollectionActive();
9092
System.out.println("remote collection active: " + remoteCollectionActive);

0 commit comments

Comments
 (0)