CableConnector: Receive wave data via CAT connection

pull/67/head
Sunguk Lee 2023-08-07 03:56:34 +09:00
rodzic ff4db69b61
commit a37a5307f7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 20A74A5D37EEA757
3 zmienionych plików z 64 dodań i 3 usunięć

Wyświetl plik

@ -355,13 +355,26 @@ public class MainViewModel extends ViewModel {
//创建发射对象回调发射前发射后、QSL成功后。
ft8TransmitSignal = new FT8TransmitSignal(databaseOpr, new OnDoTransmitted() {
private boolean needControlSco() {
if (GeneralVariables.connectMode == ConnectMode.NETWORK) {
return false;
}
if (GeneralVariables.controlMode != ControlMode.CAT) {
return true;
}
if (baseRig != null && !baseRig.supportWaveOverCAT()) {
return true;
}
return false;
}
@Override
public void onBeforeTransmit(Ft8Message message, int functionOder) {
if (GeneralVariables.controlMode == ControlMode.CAT
|| GeneralVariables.controlMode == ControlMode.RTS
|| GeneralVariables.controlMode == ControlMode.DTR) {
if (baseRig != null) {
if (GeneralVariables.connectMode != ConnectMode.NETWORK) stopSco();
if (needControlSco()) stopSco();
baseRig.setPTT(true);
}
}
@ -379,7 +392,7 @@ public class MainViewModel extends ViewModel {
|| GeneralVariables.controlMode == ControlMode.DTR) {
if (baseRig != null) {
baseRig.setPTT(false);
if (GeneralVariables.connectMode != ConnectMode.NETWORK) startSco();
if (needControlSco()) startSco();
}
}
}
@ -601,6 +614,13 @@ public class MainViewModel extends ViewModel {
baseRig.setControlMode(GeneralVariables.controlMode);
CableConnector connector = new CableConnector(context, port, GeneralVariables.baudRate
, GeneralVariables.controlMode, baseRig);
connector.setOnCableDataReceived(new CableConnector.OnCableDataReceived() {
@Override
public void OnWaveReceived(int bufferLen, float[] buffer) {
Log.i(TAG, "call hamRecorder.doOnWaveDataReceived");
hamRecorder.doOnWaveDataReceived(bufferLen, buffer);
}
});
baseRig.setOnRigStateChanged(onRigStateChanged);
baseRig.setConnector(connector);
connector.connect();

Wyświetl plik

@ -78,6 +78,17 @@ public class BaseRigConnector {
//留给网络方式发送音频流
}
public void receiveWaveData(byte[] data){
float[] waveFloat=new float[data.length/2];
for (int i = 0; i <waveFloat.length ; i++) {
waveFloat[i]=readShortBigEndianData(data,i*2)/32768.0f;
}
receiveWaveData(waveFloat);
}
public void receiveWaveData(float[] data){
}
public OnConnectReceiveData getOnConnectReceiveData() {
return onConnectReceiveData;
}
@ -100,4 +111,17 @@ public class BaseRigConnector {
public boolean isConnected(){
return connected;
}
/**
* Short
*
* @param data
* @param start
* @return Int16
*/
public static short readShortBigEndianData(byte[] data, int start) {
if (data.length - start < 2) return 0;
return (short) ((short) data[start] & 0xff
| ((short) data[start + 1] & 0xff) << 8);
}
}

Wyświetl plik

@ -15,10 +15,13 @@ import com.bg7yoz.ft8cn.serialport.util.SerialInputOutputManager;
*/
public class CableConnector extends BaseRigConnector {
private static final String TAG="CableConnector";
public interface OnCableDataReceived {
void OnWaveReceived(int bufferLen,float[] buffer);
}
private final CableSerialPort cableSerialPort;
private final BaseRig cableConnectedRig;
private OnCableDataReceived onCableDataReceived;
public CableConnector(Context context,CableSerialPort.SerialPort serialPort, int baudRate
, int controlMode, BaseRig cableConnectedRig) {
@ -71,6 +74,20 @@ public class CableConnector extends BaseRigConnector {
// sendData(wave);
}
@Override
public void receiveWaveData(float[] data){
Log.i(TAG, "received wave data");
if (onCableDataReceived!=null){
Log.i(TAG, "call onCableDataReceived.OnWaveReceived");
onCableDataReceived.OnWaveReceived(data.length,data);
}
}
public void setOnCableDataReceived(OnCableDataReceived onCableDataReceived) {
this.onCableDataReceived = onCableDataReceived;
}
@Override
public void connect() {
super.connect();