Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 132a1fc

Browse files
committed
Allow SerialReader to read long json strings
1 parent 75146f9 commit 132a1fc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Diff for: src/main/java/nz/co/fortytwo/signalk/server/SerialPortReader.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public class SerialReader implements SerialPortEventListener {
160160
private Pattern uid;
161161
List<String> lines = new ArrayList<String>();
162162
String line = null;
163+
StringBuffer lineBuf = new StringBuffer();
163164
private boolean enableSerial=true;
164165
private boolean complete;
165166
protected InputStream in;
@@ -197,8 +198,10 @@ public void serialEvent(SerialPortEvent event) {
197198

198199
//10=LF, 13=CR, lines should end in CR/LF
199200
if(r==10 ||x==256){
200-
if(r==10)complete=true;
201-
line = new String(buff);
201+
if(r==10){
202+
complete=true;
203+
}
204+
lineBuf.append(buff);
202205
buff=new byte[256];
203206
x=0;
204207
}
@@ -209,16 +212,16 @@ public void serialEvent(SerialPortEvent event) {
209212
return;
210213
}
211214
//we have a line ending in CR/LF
212-
if (complete && StringUtils.isNotBlank(line)) {
213-
line = line.trim();
215+
if (complete && StringUtils.isNotBlank(lineBuf)) {
216+
line = lineBuf.toString().trim();
214217
if(logger.isDebugEnabled())logger.debug(portName + ":Serial Received:" + line);
215218
//its not empty!
216219
if(line.length()>0){
217220
//map it if we havent already
218221
if (!mapped && uid.matcher(line).matches()) {
219222
// add to map
220223
logger.debug(portName + ":Serial Received:" + line);
221-
String type = StringUtils.substringBetween(line, ConfigConstants.UID + ":", ",");
224+
String type = StringUtils.substringBetween(line.toString(), ConfigConstants.UID + ":", ",");
222225
if (type != null) {
223226
logger.debug(portName + ": device name:" + type);
224227
deviceType = type.trim();
@@ -244,6 +247,7 @@ public void serialEvent(SerialPortEvent event) {
244247
}
245248
complete=false;
246249
line=null;
250+
lineBuf= new StringBuffer();
247251
}
248252
}
249253
}

0 commit comments

Comments
 (0)