Skip to content

Commit ebc174a

Browse files
committed
Merge branch 'BenjaminRenz-master'
2 parents 45122f6 + 8db72f7 commit ebc174a

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

OpenGammaTool/src/com/gammascout/AboutDialog.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public AboutDialog()
7070
dtrpnOpenGammaTool.setBackground(UIManager
7171
.getColor("Button.background"));
7272
dtrpnOpenGammaTool
73-
.setText("<html><body>\nOpen Gamma Tool<br/>\nVersion 1.3 (beta)<br/>\n&#169; 2014-2019 Erik Berglund<br/>\n<br/>\nSpecial thanks to <a href=\"http://johannes-bauer.com/linux/gammascout/\">Johannes Bauer</a><br/>\nfor reverse engineering and documenting <br/>\nthe GammaScout&#8482; protocol<br/>\n</body></html>");
73+
.setText("<html><body>\nOpen Gamma Tool<br/>\nVersion 1.3 (beta)<br/>\n&#169; 2014-2019 Erik Berglund<br/>\n<br/>"
74+
+ "\nSpecial thanks to <a href=\"http://johannes-bauer.com/linux/gammascout/\">Johannes Bauer</a><br/>\nfor reverse engineering and documenting <br/>\nthe GammaScout&#8482; protocol.<br/><br/>"
75+
+ "\nThanks to <a href=\"https://github.com/BenjaminRenz\">Benjamin Renz</a> for his work on the GammaScout&#8482; version 1 protocol.<br/>\n</body></html>");
7476
GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
7577
gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(
7678
Alignment.TRAILING).addGroup(

OpenGammaTool/src/com/gammascout/MainWindow.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,24 @@ else if (portNames.length == 1)
626626
if (portName != null)
627627
{
628628
ProtocolVersion version = new ProtocolVersionDetector(portName).getVersion();
629-
switch (version)
629+
if(version != null)
630630
{
631-
case VERSION1:
632-
gsc = new GammaScoutConnectorV1(portName);
633-
break;
634-
case VERSION2:
635-
gsc = new GammaScoutConnectorV2(portName);
636-
break;
637-
default:
638-
System.out.println("Couldn't determine protocol version.");
639-
break;
631+
switch (version)
632+
{
633+
case VERSION1:
634+
gsc = new GammaScoutConnectorV1(portName);
635+
break;
636+
case VERSION2:
637+
gsc = new GammaScoutConnectorV2(portName);
638+
break;
639+
default:
640+
System.out.println("Couldn't determine protocol version.");
641+
break;
642+
}
643+
}
644+
else
645+
{
646+
System.out.println("Protocol version detection failed.");
640647
}
641648
if(gsc!=null)
642649
{

OpenGammaTool/src/com/gammascout/usb/GammaScoutConnectorV1.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ public GammaScoutConnectorV1(String portname) throws SerialPortException
6464
connected = true;
6565
}
6666

67+
protected boolean bytesAvailable() {
68+
String first = peek();
69+
if (first == null) { //no new byte available return directely
70+
return false;
71+
}
72+
if (first.equals("fe") && lineBuffer.size() < 6) {
73+
return false;//note enough data for date change command (6 bytes)
74+
} else if (first.equals("ff") && lineBuffer.size() < 5){
75+
return false;//note enough data for time change command (5 bytes)
76+
} else if (first.equals("f4") || first.equals("f3") ||first.equals("f2") || first.equals("f1")|| first.equals("f0")){
77+
return true;//one byte command do not care if there is none left in the buffer
78+
}else{//actual value incoming, we need at least two bytes
79+
if(lineBuffer.size()>=2){
80+
return true;
81+
}else {
82+
return false;
83+
}
84+
}
85+
}
86+
6787
@Override
6888
protected void readAvailableDataString() throws Exception
6989
{
@@ -87,6 +107,10 @@ protected void readAvailableDataString() throws Exception
87107
}
88108
}
89109
}
110+
if (totalBytesRead >= bytesUsed)
111+
{
112+
break;
113+
}
90114
}
91115
}
92116
}
@@ -126,15 +150,16 @@ public List<Reading> getLog() throws Exception
126150
line = buffer.remove(0);
127151
System.out.println("Read: \"" + line+"\"");
128152
totalBytesRead+=(line.length()-7)/3;
129-
String addressString = line.substring(6, 8)+line.substring(9,11);
153+
String addressString = line.substring(9,11)+line.substring(6, 8);
130154
bytesUsed = Integer.parseInt(addressString,16);
155+
System.out.println("Expecting "+bytesUsed.toString()+" bytes to arrive or in hex address read till: "+addressString);
131156
// Skip to address 0x100
132157
while(totalBytesRead < 0x100)
133158
{
134159
waitForBuffer();
135160
line = buffer.remove(0);
136161
System.out.println("Read: \"" + line+"\"");
137-
totalBytesRead+=(line.length()-7)/3; //This does not account for spaces and newline
162+
totalBytesRead+=(line.length()-7)/3;
138163
}
139164

140165
// read data lines
@@ -149,11 +174,8 @@ public List<Reading> getLog() throws Exception
149174
switch (next)
150175
{
151176
case "fe":
177+
System.out.println("changing DateFormat");
152178
// set date
153-
while(this.lineBuffer.size()<5) { //pops can be new line witch hasn't arrived yet
154-
waitForBuffer();
155-
readAvailableDataString();
156-
}
157179
String mm = pop();
158180
String HH = pop();
159181
String dd = pop();
@@ -166,10 +188,7 @@ public List<Reading> getLog() throws Exception
166188
break;
167189
case "ff":
168190
{
169-
while(this.lineBuffer.size()<4){ //pops can be new line witch hasn't arrived yet
170-
waitForBuffer();
171-
readAvailableDataString();
172-
}
191+
System.out.println("Got new interval");
173192
String g1 = pop();
174193
String g2 = pop();
175194
// Give the number of seconds elapsed
@@ -212,24 +231,24 @@ public List<Reading> getLog() throws Exception
212231
else
213232
{
214233
// decode impulse count
215-
while(this.lineBuffer.size()<1){ //second pop can be new line witch hasn't arrived yet
216-
waitForBuffer();
217-
readAvailableDataString();
218-
}
219-
long count = decodeCount(next, pop());
234+
235+
long count = decodeCount(next, pop());
220236
// update time
221237
currentLogTime += intervalSeconds * 1000;
222238
Reading r = new Reading(intervalSeconds, count, currentLogTime);
223239
readings.add(r);
224240
announceReading(r);
241+
System.out.println("Got new impulse with:"+ Long.toString(count));
225242
}
226243
break;
227244
}
228245

229246
}
230247
if (totalBytesRead >= this.bytesUsed)
231248
{
232-
System.out.println("finished reading data");
249+
System.out.println("finished reading data...");
250+
System.out.println("please wait before sending any further commands like set date/time or clearing storage because");
251+
System.out.println("the device still sends data and does not respond to any querries within about 1 minute");
233252
break;
234253
}
235254
}

OpenGammaTool/src/com/gammascout/usb/GammaScoutConnectorV2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public void setClock(Date time) throws SerialPortException
103103
{
104104
Tools.sleep(500);
105105
}
106-
waitForString("\r\n");
107-
waitForString("Datum und Zeit gestellt\r\n");
108106
}
107+
waitForString("\r\n");
108+
waitForString("Datum und Zeit gestellt\r\n");
109109
updateInfo();
110110
setPcMode(false);
111111
}

OpenGammaTool/src/com/gammascout/usb/ProtocolVersionDetector.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ private ProtocolVersion innerTest(SerialPort serial) throws SerialPortException
8181
try
8282
{
8383
String prelude = serial.readString(10, 1000);
84-
System.out.println("Read \""+prelude+"\"");
8584
if(prelude.startsWith("\r\n Vers"))
8685
{
8786
result = ProtocolVersion.VERSION1;
@@ -94,13 +93,11 @@ else if(prelude.startsWith("\r\nVers") || prelude.startsWith("\r\nStand"))
9493
}
9594
catch (SerialPortTimeoutException e)
9695
{
97-
System.out.println("Timed out waiting for response.");
98-
e.printStackTrace();
96+
// Do nothing, this is expected if we're using the wrong protocol version.
9997
}
10098
finally
10199
{
102100
String remainder = serial.readString();
103-
System.out.println("Read \""+remainder+"\"");
104101
serial.closePort();
105102
}
106103
return result;

0 commit comments

Comments
 (0)