Skip to content

Commit ae3ab8b

Browse files
committed
Merge branch 'master' of
https://github.com/NeuronRobotics/java-bowler.git Conflicts: javasdk/NRSDK/lib/nrjavaserial-3.9.0.jar
2 parents 257ea2a + 9a367e0 commit ae3ab8b

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed
-697 Bytes
Binary file not shown.

javasdk/NRSDK/src/com/neuronrobotics/sdk/common/BowlerDatagram.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,19 @@ public void setFree(boolean isFree, BowlerDatagramFactory factory) {
437437
setFree(isFree);
438438
}
439439

440+
private void setNotFree(){
441+
clear();
442+
timeout.stop();
443+
}
444+
445+
private void setToFree(){
446+
timeout.initialize(BowlerDatagramFactory.getPacketTimeout(), this);
447+
}
440448
void setFree(boolean isFree) {
441449
if(isFree== true){
442-
clear();
443-
timeout.stop();
450+
setNotFree();
444451
}else{
445-
timeout.initialize(BowlerDatagramFactory.getPacketTimeout(), this);
452+
setToFree();
446453
}
447454
this.isPackedAvailibleForLoading = isFree;
448455
}

javasdk/NRSDK/src/com/neuronrobotics/sdk/common/BowlerDatagramFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class BowlerDatagramFactory {
2828

2929
private static BowlerDatagram pool [];
3030
private static int failed=0;
31+
private static int lastIndex = 0;
3132
private static int poolDefaultSize = 1500;
3233
private static long packetTimeout = 2000;
3334

@@ -57,11 +58,20 @@ private static synchronized BowlerDatagram getNextPacket(){
5758
BowlerDatagram ref = null;
5859

5960
//Find the most recent free packet from the pool
60-
for(int i=0;(i<pool.length && ref==null);i++){
61+
for(int i=lastIndex;(i<pool.length && ref==null);i++){
6162
//Log.warning("Checking pool packet "+i);
6263
if(pool[i].isFree()){
64+
lastIndex=i;
6365
ref=pool[i];
6466
}
67+
if(i==pool.length-1){
68+
//loop around since we started at the last index
69+
i=0;
70+
}
71+
if(i==lastIndex-1){
72+
//looped around, bail
73+
i=pool.length;
74+
}
6575
}
6676
if(ref == null){
6777
//The whole list was search and no free packets were found

javasdk/NRSDK/src/com/neuronrobotics/sdk/common/ThreadedTimeout.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public boolean isTimedOut() {
5757
}
5858

5959
public void initialize(long sleepTime,IthreadedTimoutListener listener) {
60-
stop();
61-
this.time = (sleepTime);
60+
//stop();
6261
setStartTime(System.currentTimeMillis());
62+
this.time = (sleepTime);
6363
setTimeoutListener(listener);
64-
timerThread.addTimer(this);
64+
//timerThread.addTimer(this);
6565
}
6666

6767
public long getAmountOfTimeForTimerToRun() {
@@ -83,6 +83,7 @@ public void run(){
8383
while(true){
8484
if(getTimers().size()>0){
8585
toRemove.clear();
86+
8687
for(int i=0;i<getTimers().size();i++){
8788
try{
8889
ThreadedTimeout t = getTimers().get(i);
@@ -112,15 +113,15 @@ public void addTimer(ThreadedTimeout time){
112113
if(!getTimers().contains(time))
113114
getTimers().add(time);
114115
}catch (Exception e){
115-
116+
e.printStackTrace();
116117
}
117118
}
118119
public void removeTimer(ThreadedTimeout time){
119120
try{
120121
if(getTimers().contains(time))
121122
getTimers().remove(time);
122123
}catch (Exception e){
123-
124+
e.printStackTrace();
124125
}
125126

126127
}

0 commit comments

Comments
 (0)