legacy
sh123 2022-08-02 13:48:57 +03:00
rodzic 2b0f1609b1
commit b408a24b9a
4 zmienionych plików z 34 dodań i 7 usunięć

Wyświetl plik

@ -88,18 +88,32 @@ public class Hdlc implements Protocol {
if (_readByte == 0x7e) {
Log.i(TAG, "HDLC " + _prevHdlc/8);
int pos = _currentFrameBuffer.position();
// shift/flush back previous 8 - 1 bits
if (pos >= 7) {
_currentFrameBuffer.position(_currentFrameBuffer.position() - 7);
} else {
_currentFrameBuffer.position(0);
}
// get packet bits between 0x7e
_currentFrameBuffer.flip();
byte[] packetBits = new byte[_currentFrameBuffer.remaining()];
_currentFrameBuffer.get(packetBits);
// get bytes from bits
byte[] packetBytes = BitTools.convertFromHDLCBitArray(packetBits);
if (packetBytes != null) {
Log.i(TAG, DebugTools.byteBitsToString(packetBits));
Log.i(TAG, DebugTools.bytesToHex(packetBytes));
if (packetBytes.length > 2) {
byte[] contentBytes = Arrays.copyOf(packetBytes, packetBytes.length - 2);
int calculatedCrc = ChecksumTools.calculateFcs(contentBytes);
int packetCrc = ((int)packetBytes[packetBytes.length - 2] & 0xff) | (((int)packetBytes[packetBytes.length - 1] & 0xff) << 8);
Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
if (calculatedCrc == packetCrc) {
Log.i(TAG, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
}
_currentFrameBuffer.clear();
_readByte = 0;
@ -147,6 +161,8 @@ public class Hdlc implements Protocol {
buffer.flip();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
Log.i(TAG, DebugTools.bytesToHex(data));
byte[] dataBytesAsBits = BitTools.convertToHDLCBitArray(data, true);
// add preamble

Wyświetl plik

@ -77,8 +77,7 @@ public class BitTools {
boolean skipNext = false;
StringBuffer s = new StringBuffer();
int cntBits = 0;
for (int i = 0; i < dataBitsAsBytes.length; i++) {
byte currentBit = dataBitsAsBytes[i];
for (byte currentBit : dataBitsAsBytes) {
if (skipNext) {
// cannot have 6 consecutive 1, non-HDLC data
if (currentBit == 1) return null;
@ -94,9 +93,12 @@ public class BitTools {
} else {
cntOnes = 0;
}
if (i % 8 == 7) {
if (cntBits % 8 == 3) {
s.append(':');
}
if (cntBits % 8 == 7) {
s.append(' ');
byteBuffer.put((byte)(currentByte & 0xff));
byteBuffer.put((byte) (currentByte & 0xff));
currentByte = 0;
}
// 5 ones, skip next

Wyświetl plik

@ -13,6 +13,7 @@ import android.util.Log;
import androidx.preference.PreferenceManager;
import com.radio.codec2talkie.settings.PreferenceKeys;
import com.radio.codec2talkie.tools.AudioTools;
import com.radio.codec2talkie.tools.BitTools;
import com.radio.codec2talkie.tools.DebugTools;
import com.ustadmobile.codec2.Codec2;
@ -45,6 +46,7 @@ public class SoundModem implements Transport, Runnable {
private final SharedPreferences _sharedPreferences;
private boolean _isRunning = true;
private final boolean _loopbackTest = false;
private final long _fskModem;
@ -69,7 +71,8 @@ public class SoundModem implements Transport, Runnable {
constructSystemAudioDevices();
new Thread(this).start();
if (!_loopbackTest)
new Thread(this).start();
}
private void constructSystemAudioDevices() {
@ -122,7 +125,7 @@ public class SoundModem implements Transport, Runnable {
_bitBuffer.flip();
int len = _bitBuffer.remaining();
_bitBuffer.get(data, 0, len);
//Log.i(TAG, "-- " + DebugTools.byteBitsToString(data));
//Log.i(TAG, "read " + DebugTools.byteBitsToString(data));
_bitBuffer.compact();
return len;
}
@ -134,6 +137,11 @@ public class SoundModem implements Transport, Runnable {
public int write(byte[] srcDataBytesAsBits) throws IOException {
byte[] dataBytesAsBits = BitTools.convertToNRZI(srcDataBytesAsBits);
if (_loopbackTest) {
Log.i(TAG, "write " + DebugTools.byteBitsToString(srcDataBytesAsBits));
_bitBuffer.put(BitTools.convertFromNRZI(dataBytesAsBits, (byte) 0));
}
int j = 0;
for (int i = 0; i < dataBytesAsBits.length; i++, j++) {
if (j >= _playbackBitBuffer.length) {
@ -168,6 +176,7 @@ public class SoundModem implements Transport, Runnable {
while (_isRunning) {
// TODO, take readCnt into account, do not read if playback is active
int readCnt = _systemAudioRecorder.read(_recordAudioBuffer, 0, Codec2.fskNin(_fskModem));
//Log.i(TAG, "! " + AudioTools.getSampleLevelDb(Arrays.copyOf(_recordAudioBuffer, Codec2.fskNin(_fskModem))));
//Log.i(TAG, DebugTools.shortsToHex(_recordAudioBuffer));
//Log.i(TAG, readCnt + " " + _recordAudioBuffer.length + " " + Codec2.fskNin(_fskModem));
Codec2.fskDemodulate(_fskModem, _recordAudioBuffer, _recordBitBuffer);

Wyświetl plik

@ -74,7 +74,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
conFsk->demodBits = (uint8_t*)malloc(sizeof(uint8_t) * fsk->Nbits);
conFsk->demodBuf = (int16_t*)malloc(sizeof(short) * (fsk->N + 2 * fsk->Ts));
fsk_set_freq_est_limits(fsk, -sampleFrequency / 2, sampleFrequency / 2);
fsk_set_freq_est_limits(fsk, 500, 2700);
fsk_set_freq_est_alg(fsk, 1);
auto pv = (unsigned long) conFsk;