Skip to content

Commit b7fb77a

Browse files
authored
Merge branch 'master' into DEV-1198_reenable_excluded_driverpc_tests
2 parents 934c25e + 0e28afb commit b7fb77a

10 files changed

Lines changed: 833 additions & 90 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 362 additions & 0 deletions
Large diffs are not rendered by default.

‎AGENTS.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ all: they are legacy Eclipse ADT Android projects.
1818

1919
Test results land in `**/build/test-results/test/*.xml`.
2020

21+
## Releasing
22+
Releases are cut by the **Release Java API** workflow (`release.yml`), not from a developer machine,
23+
and need no uprev PR:
24+
1. Run the workflow on `master`. Leave `version` blank for the next patch after the last `API_v`
25+
release, or type one. It tests and builds as CI does, publishes all three artifacts to GitHub
26+
Packages in one `gradlew publish`, tags `API_v<version>`, and creates the GitHub Release with the
27+
jars attached (not marked Latest — that stays with Consensys).
28+
2. It also builds `ShimmerJavaClass.jar` for MATLAB and opens a PR replacing
29+
`Shimmer-MATLAB-ID/libs/ShimmerJavaClass.jar` (needs the `MATLAB_REPO_TOKEN` secret). Review and
30+
merge it.
31+
3. Run `ShimmerAndroidAPI`'s own Release workflow, which builds against the newest Java release unless
32+
told otherwise.
33+
34+
The version is not stored in the source: the three publishing blocks read `-PreleaseVersion`, which
35+
the workflow passes, and fall back to `local`. The `API_v` tags are the record of what was released.
36+
37+
`ShimmerJavaClass.jar` must be Java 8 bytecode, because MATLAB may load it on Java 8. Build it locally
38+
with `cd ShimmerDriverPC && ./gradlew shadowJar -PmatlabJava8`, which compiles all three projects with
39+
`--release 8` — that also rejects any API newer than Java 8, so `Process.onExit()`, `var` and the like
40+
fail the build here instead of throwing `NoSuchMethodError` inside MATLAB.
41+
2142
## Subprojects
2243
| Project | Role |
2344
|---|---|

‎ShimmerBluetoothManager/build.gradle‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ publishing {
2727

2828
groupId = 'com.shimmerresearch' // Replace with your package's group/organization name
2929
artifactId = 'shimmerbluetoothmanager' // Replace with the name of your package
30-
version = '0.11.8_beta' // Replace with your package version
30+
version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion)
3131

3232
// Jar publication
3333
//(
@@ -40,7 +40,7 @@ publishing {
4040
repositories {
4141
maven {
4242
name = "GitHubPackages"
43-
url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API")
43+
url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API")
4444
credentials {
4545
/* Create gradle.properties file in GRADLE_USER_HOME/.gradle/
4646
(e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your
@@ -68,3 +68,14 @@ dependencies {
6868
// 'test.useTestNG()' to your build script.
6969
testImplementation 'junit:junit:4.12'
7070
}
71+
72+
// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be
73+
// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected.
74+
tasks.withType(PublishToMavenRepository).configureEach {
75+
doFirst {
76+
if (publication.version == 'local') {
77+
throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " +
78+
"Release with the Release Java API workflow, or pass -PreleaseVersion.")
79+
}
80+
}
81+
}

‎ShimmerDriver/build.gradle‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ publishing {
4949

5050
groupId = 'com.shimmerresearch' // Replace with your package's group/organization name
5151
artifactId = 'shimmerdriver' // Replace with the name of your package
52-
version = '0.11.8_beta' // Replace with your package version
52+
version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion)
5353

5454
// Jar publication
5555
//(
@@ -63,7 +63,7 @@ publishing {
6363
repositories {
6464
maven {
6565
name = "GitHubPackages"
66-
url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API")
66+
url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API")
6767
credentials {
6868
/* Create gradle.properties file in GRADLE_USER_HOME/.gradle/
6969
(e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your
@@ -173,3 +173,14 @@ tasks.withType(Test).configureEach {
173173
}
174174
}
175175

176+
177+
// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be
178+
// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected.
179+
tasks.withType(PublishToMavenRepository).configureEach {
180+
doFirst {
181+
if (publication.version == 'local') {
182+
throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " +
183+
"Release with the Release Java API workflow, or pass -PreleaseVersion.")
184+
}
185+
}
186+
}

‎ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java‎

Lines changed: 101 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,22 +1052,34 @@ else if(isSupportedInStreamCmds() && bufferTemp[getPacketSizeWithCrc()+2]==INSTR
10521052
printLogDataForDebugging("COMMAND TXed and ACK RECEIVED IN STREAM");
10531053
printLogDataForDebugging("INS CMD RESP");
10541054

1055-
//Firstly handle the in-stream response
1056-
stopTimerCheckForAckOrResp(); //cancel the ack timer
1057-
mWaitForResponse=false;
1058-
mWaitForAck=false;
1055+
// The firmware also sends a status response unprompted (on a dock or
1056+
// undock, the user button, a low-battery stop), so this completes the
1057+
// command in flight only if the response is that command's reply
1058+
byte[] inStreamResponseCommand = readBytes(1, INSTREAM_CMD_RESPONSE);
1059+
boolean isReplyToCommandInFlight = inStreamResponseCommand!=null
1060+
&& isReplyToCommandInFlight(inStreamResponseCommand[0]);
1061+
if(isReplyToCommandInFlight){
1062+
stopTimerCheckForAckOrResp(); //cancel the ack timer
1063+
mWaitForResponse=false;
1064+
mWaitForAck=false;
1065+
}
10591066

1060-
processInstreamResponse(true);
1067+
//Firstly handle the in-stream response
1068+
if(inStreamResponseCommand!=null){
1069+
processInstreamResponse(inStreamResponseCommand[0], true);
1070+
}
10611071

1062-
// Need to remove here because it is an
1063-
// in-stream response while streaming so not
1064-
// handled elsewhere
1065-
if(getListofInstructions().size()>0){
1066-
removeInstruction(0);
1072+
if(isReplyToCommandInFlight){
1073+
// Need to remove here because it is an
1074+
// in-stream response while streaming so not
1075+
// handled elsewhere
1076+
if(getListofInstructions().size()>0){
1077+
removeInstruction(0);
1078+
}
1079+
1080+
mTransactionCompleted=true;
1081+
setInstructionStackLock(false);
10671082
}
1068-
1069-
mTransactionCompleted=true;
1070-
setInstructionStackLock(false);
10711083

10721084
//Then process the Data packet
10731085
processDataPacket(bufferTemp);
@@ -1203,76 +1215,94 @@ else if(currentCommand==GET_INFOMEM_COMMAND || currentCommand==GET_CALIB_DUMP_CO
12031215
}
12041216
}
12051217

1218+
/**
1219+
* Whether an in-stream response is the reply to the command in flight. The
1220+
* protocol matches a reply to its command by the response opcode, never by the
1221+
* ACK (log-and-stream-common docs/SHIMMER3_BT_COMMUNICATION_PROTOCOL.md
1222+
* section 5.4, rule 2).
1223+
*/
1224+
private boolean isReplyToCommandInFlight(byte inStreamResponseCommand) {
1225+
if(!mWaitForAck && !mWaitForResponse){
1226+
return false;
1227+
}
1228+
BtCommandDetails commandDetails = mBtGetCommandMap.get(mCurrentCommand);
1229+
return commandDetails!=null && commandDetails.expectedResponse==inStreamResponseCommand;
1230+
}
1231+
12061232
/** process responses to in-stream response */
12071233
protected void processInstreamResponse(boolean shouldClearCrcFromBuffer) {
1208-
boolean responseWasParsed = true;
1209-
12101234
byte[] inStreamResponseCommandBuffer = readBytes(1, INSTREAM_CMD_RESPONSE);
12111235
if(inStreamResponseCommandBuffer!=null){
1212-
byte inStreamResponseCommand = inStreamResponseCommandBuffer[0];
1213-
consolePrintLn("In-stream received = " + btCommandToString(inStreamResponseCommand));
1236+
processInstreamResponse(inStreamResponseCommandBuffer[0], shouldClearCrcFromBuffer);
1237+
}
1238+
}
12141239

1215-
if(inStreamResponseCommand==DIR_RESPONSE){
1216-
byte[] responseData = readBytes(1, inStreamResponseCommand);
1217-
if(responseData!=null){
1218-
int directoryNameLength = responseData[0];
1219-
byte[] bufferDirectoryName = new byte[directoryNameLength];
1220-
bufferDirectoryName = readBytes(directoryNameLength, inStreamResponseCommand);
1221-
if(bufferDirectoryName!=null){
1222-
String tempDirectory = new String(bufferDirectoryName);
1223-
mDirectoryName = tempDirectory;
1224-
printLogDataForDebugging("Directory Name = " + mDirectoryName);
1225-
}
1240+
/** process an in-stream response whose response command has already been read */
1241+
protected void processInstreamResponse(byte inStreamResponseCommand, boolean shouldClearCrcFromBuffer) {
1242+
boolean responseWasParsed = true;
1243+
1244+
consolePrintLn("In-stream received = " + btCommandToString(inStreamResponseCommand));
1245+
1246+
if(inStreamResponseCommand==DIR_RESPONSE){
1247+
byte[] responseData = readBytes(1, inStreamResponseCommand);
1248+
if(responseData!=null){
1249+
int directoryNameLength = responseData[0];
1250+
byte[] bufferDirectoryName = new byte[directoryNameLength];
1251+
bufferDirectoryName = readBytes(directoryNameLength, inStreamResponseCommand);
1252+
if(bufferDirectoryName!=null){
1253+
String tempDirectory = new String(bufferDirectoryName);
1254+
mDirectoryName = tempDirectory;
1255+
printLogDataForDebugging("Directory Name = " + mDirectoryName);
12261256
}
12271257
}
1228-
else if(inStreamResponseCommand==STATUS_RESPONSE){
1229-
int statusBytesToRead = 0;
1230-
if(isSupportedUSBPluggedInStatus()) {
1231-
statusBytesToRead = 2;
1232-
}else {
1233-
statusBytesToRead = 1;
1234-
}
1235-
byte[] responseData = readBytes(statusBytesToRead, inStreamResponseCommand);
1236-
if(responseData!=null){
1237-
parseStatusByte(responseData);
1238-
1239-
if(!isSupportedRtcStateInStatus()){
1240-
if(!mIsSensing && !isInitialised()){
1241-
writeRealTimeClock();
1242-
}
1243-
} else {
1244-
//New case to make sure RTC is set if it hasn't been already
1245-
if(!isSDLogging() && (!isInitialised() || !mIsRtcSet)){
1246-
writeRealTimeClock();
1247-
}
1258+
}
1259+
else if(inStreamResponseCommand==STATUS_RESPONSE){
1260+
int statusBytesToRead = 0;
1261+
if(isSupportedUSBPluggedInStatus()) {
1262+
statusBytesToRead = 2;
1263+
}else {
1264+
statusBytesToRead = 1;
1265+
}
1266+
byte[] responseData = readBytes(statusBytesToRead, inStreamResponseCommand);
1267+
if(responseData!=null){
1268+
parseStatusByte(responseData);
1269+
1270+
if(!isSupportedRtcStateInStatus()){
1271+
if(!mIsSensing && !isInitialised()){
1272+
writeRealTimeClock();
1273+
}
1274+
} else {
1275+
//New case to make sure RTC is set if it hasn't been already
1276+
if(!isSDLogging() && (!isInitialised() || !mIsRtcSet)){
1277+
writeRealTimeClock();
12481278
}
1249-
1250-
eventLogAndStreamStatusChanged(mCurrentCommand);
1251-
}
1252-
}
1253-
else if(inStreamResponseCommand==VBATT_RESPONSE) {
1254-
byte[] responseData = readBytes(3, inStreamResponseCommand);
1255-
if(responseData!=null){
1256-
ShimmerBattStatusDetails battStatusDetails = new ShimmerBattStatusDetails(((responseData[1]&0xFF)<<8)+(responseData[0]&0xFF),responseData[2]);
1257-
setBattStatusDetails(battStatusDetails);
1258-
printLogDataForDebugging("Battery Status:"
1259-
+ "\tVoltage=" + battStatusDetails.getBattVoltageParsed()
1260-
+ "\tCharging status=" + battStatusDetails.getChargingStatusParsed()
1261-
+ "\tBatt %=" + battStatusDetails.getEstimatedChargePercentageParsed());
12621279
}
1280+
1281+
eventLogAndStreamStatusChanged(mCurrentCommand);
12631282
}
1264-
else
1265-
{
1266-
responseWasParsed = false;
1267-
}
1268-
1269-
if (shouldClearCrcFromBuffer && mBtCommsCrcModeCurrent != BT_CRC_MODE.OFF && responseWasParsed) {
1270-
// The driver doesn't currently support checking of CRC bytes on any response
1271-
// other then data packets but we still need to clear them from the buffer if
1272-
// CRC is enabled.
1273-
clearCrcBytesFromBuffer(inStreamResponseCommand);
1283+
}
1284+
else if(inStreamResponseCommand==VBATT_RESPONSE) {
1285+
byte[] responseData = readBytes(3, inStreamResponseCommand);
1286+
if(responseData!=null){
1287+
ShimmerBattStatusDetails battStatusDetails = new ShimmerBattStatusDetails(((responseData[1]&0xFF)<<8)+(responseData[0]&0xFF),responseData[2]);
1288+
setBattStatusDetails(battStatusDetails);
1289+
printLogDataForDebugging("Battery Status:"
1290+
+ "\tVoltage=" + battStatusDetails.getBattVoltageParsed()
1291+
+ "\tCharging status=" + battStatusDetails.getChargingStatusParsed()
1292+
+ "\tBatt %=" + battStatusDetails.getEstimatedChargePercentageParsed());
12741293
}
12751294
}
1295+
else
1296+
{
1297+
responseWasParsed = false;
1298+
}
1299+
1300+
if (shouldClearCrcFromBuffer && mBtCommsCrcModeCurrent != BT_CRC_MODE.OFF && responseWasParsed) {
1301+
// The driver doesn't currently support checking of CRC bytes on any response
1302+
// other then data packets but we still need to clear them from the buffer if
1303+
// CRC is enabled.
1304+
clearCrcBytesFromBuffer(inStreamResponseCommand);
1305+
}
12761306

12771307
}
12781308

‎ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,20 @@ public int startServer() throws Exception {
153153
e.printStackTrace();
154154
}
155155
});
156-
runningProcess.onExit().thenAccept(p -> {
157-
int code = p.exitValue();
158-
System.err.println("[BLEGrpcServer] exited: code=" + code +
159-
(code >= 128 ? " (likely signal " + (code - 128) + ")" : ""));
160-
});
156+
// Not Process.onExit(): that is Java 9+, and MATLAB loads this class on Java 8 via
157+
// ShimmerJavaClass.jar, where it throws NoSuchMethodError. Daemon, like onExit()'s pool thread.
158+
final Process process = runningProcess;
159+
Thread exitWatcher = new Thread(() -> {
160+
try {
161+
int code = process.waitFor();
162+
System.err.println("[BLEGrpcServer] exited: code=" + code +
163+
(code >= 128 ? " (likely signal " + (code - 128) + ")" : ""));
164+
} catch (InterruptedException e) {
165+
Thread.currentThread().interrupt();
166+
}
167+
}, "BLEGrpcServer-exit");
168+
exitWatcher.setDaemon(true);
169+
exitWatcher.start();
161170

162171
processThread.start();
163172
return port;

‎ShimmerDriverPC/build.gradle‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ publishing {
3838
publications {
3939
mavenJava(MavenPublication) {
4040
from components.java
41+
// The Shadow plugin adds ShimmerJavaClass.jar (no classifier) to components.java, where it
42+
// collides with the plain jar and fails publish on Gradle 8. Publish the plain jar with its
43+
// dependencies in the POM, as releases up to 0.11.7_beta did; the fat jar goes to MATLAB
44+
// and the GitHub Release instead.
45+
components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) { skip() }
4146

4247
groupId = 'com.shimmerresearch' // Replace with your package's group/organization name
4348
artifactId = 'shimmerdriverpc' // Replace with the name of your package
44-
version = '0.11.8_beta' // Replace with your package version
49+
version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion)
4550

4651
// Jar publication
4752
//(
@@ -54,7 +59,7 @@ publishing {
5459
repositories {
5560
maven {
5661
name = "GitHubPackages"
57-
url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API")
62+
url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API")
5863
credentials {
5964
/* Create gradle.properties file in GRADLE_USER_HOME/.gradle/
6065
(e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your
@@ -107,12 +112,18 @@ dependencies {
107112
implementation("org.bouncycastle:bcprov-jdk15on:1.61")
108113
}
109114

110-
// Shadow JAR task to create a runnable JAR with dependencies
111-
/*
112-
Change to using the following below for ShimmerDriverPC/ShimmerDriver/ShimmerBluetoothManager
113-
sourceCompatibility = '1.8' // Ensure code is compiled with Java 8
114-
targetCompatibility = '1.8' // Ensure bytecode is compatible with Java 8
115-
*/
115+
// Shadow JAR task to create a runnable JAR with dependencies.
116+
// ShimmerJavaClass.jar is loaded by MATLAB, which may run it on Java 8, so build it as Java 8
117+
// bytecode with: ./gradlew shadowJar -PmatlabJava8
118+
// This applies to the ShimmerDriver and ShimmerBluetoothManager subprojects too, so their build files
119+
// no longer need editing to 1.8 by hand. --release 8 also fails the compile if the code uses an API
120+
// newer than Java 8, which sourceCompatibility = '1.8' alone would let through to fail in MATLAB.
121+
// The "Release Java API" workflow builds the jar this way and opens a PR into Shimmer-MATLAB-ID/libs.
122+
if (hasProperty('matlabJava8')) {
123+
allprojects {
124+
tasks.withType(JavaCompile).configureEach { options.release = 8 }
125+
}
126+
}
116127
shadowJar {
117128
archiveBaseName.set('ShimmerJavaClass') // Use archiveBaseName instead of baseName
118129
archiveClassifier.set('') // Remove classifier so it’s named shimmerjavaclass.jar
@@ -123,3 +134,14 @@ shadowJar {
123134

124135
mergeServiceFiles() // Merges service files (if any)
125136
}
137+
138+
// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be
139+
// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected.
140+
tasks.withType(PublishToMavenRepository).configureEach {
141+
doFirst {
142+
if (publication.version == 'local') {
143+
throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " +
144+
"Release with the Release Java API workflow, or pass -PreleaseVersion.")
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)