diff --git a/codec2talkie/src/main/java/com/radio/codec2talkie/audio/AudioProcessor.java b/codec2talkie/src/main/java/com/radio/codec2talkie/audio/AudioProcessor.java index 2b783ef..0be34c8 100644 --- a/codec2talkie/src/main/java/com/radio/codec2talkie/audio/AudioProcessor.java +++ b/codec2talkie/src/main/java/com/radio/codec2talkie/audio/AudioProcessor.java @@ -16,6 +16,7 @@ import java.nio.ByteBuffer; import java.util.Timer; import java.util.TimerTask; +import com.radio.codec2talkie.connect.TcpIpSocketHandler; import com.radio.codec2talkie.protocol.Callback; import com.radio.codec2talkie.protocol.Protocol; import com.radio.codec2talkie.protocol.ProtocolFactory; diff --git a/codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Kiss.java b/codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Kiss.java index 934b784..a41d7f0 100644 --- a/codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Kiss.java +++ b/codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Kiss.java @@ -166,7 +166,7 @@ public class Kiss implements Protocol { if (_outputKissBufferPos == 0) { startKissPacket(KISS_CMD_DATA); } - // new frame does not fit, complete and create new frame + // new frame does not fit, complete, send and create new frame if ( _outputKissBufferPos + escapedFrameSize >= KISS_TX_FRAME_MAX_SIZE) { completeKissPacket(); startKissPacket(KISS_CMD_DATA); @@ -275,11 +275,11 @@ public class Kiss implements Protocol { } private void sendKissByte(byte b) { - _outputKissBuffer[_outputKissBufferPos++] = b; - if (_outputKissBufferPos > _outputKissBuffer.length) { + if (_outputKissBufferPos >= _outputKissBuffer.length) { Log.e(TAG, "Output KISS buffer overflow, discarding frame"); _outputKissBufferPos = 0; } + _outputKissBuffer[_outputKissBufferPos++] = b; } private void receiveFrameByte(byte b) { diff --git a/codec2talkie/src/main/java/com/radio/codec2talkie/transport/TcpIp.java b/codec2talkie/src/main/java/com/radio/codec2talkie/transport/TcpIp.java index 0c5816d..49b999d 100644 --- a/codec2talkie/src/main/java/com/radio/codec2talkie/transport/TcpIp.java +++ b/codec2talkie/src/main/java/com/radio/codec2talkie/transport/TcpIp.java @@ -25,7 +25,12 @@ public class TcpIp implements Transport { @Override public int read(byte[] data) throws IOException { try { - return _inputStream.read(data); + int bytesRead = _inputStream.read(data); + // connection closed + if (bytesRead == -1) { + throw new IOException(); + } + return bytesRead; } catch (SocketTimeoutException e) { return 0; }