My research showed(請參閱第5頁)可通過藍牙4.2發送的最大數據量爲257字節。爲什麼我能夠通過藍牙4.2發送超過明顯的最大數據量?
但是,我能夠在我的Python腳本和Java應用程序之間發送990個字節。爲什麼我能發送這麼多的數據?我發現有關最大數據錯誤的信息,還是發生了其他事情?
的Python藍牙腳本:
#Parameters config
sdr=RtlSdr()
sdr.fc=100e6
sdr.gain=48
sdr.rs=1.024e6
#Bluetooth connection
server_sock=BluetoothSocket(RFCOMM)
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port=server_sock.getsockname()[1]
uuid="94f39d29-7d6d-437d-973b-fba39e49d4ee"
client_sock,client_info=server_sock.accept()
while (1):
samples= sdr.read_samples(256*1024)
result=psd(samples, NFFT=70, Fc=sdr.fc/1e6, Fs=sdr.rs/1e6)
tab_freq=(result[1])
value_freq=str(tab_freq)[1:-1]
value_freq2=[format(float(v),".4f")[:6] for v in value_freq.split()]
value_freq3="\n".join(value_pxx2)
#SAME FOR POWER VALUE
#THEN I SEND DATA BY BLUETOOTH
client_sock.send(value_freq3)
的Java藍牙代碼:
private class ThreadConnected extends Thread {
private final BluetoothSocket connectedBluetoothSocket;
private final InputStream connectedInputStream;
private final OutputStream connectedOutputStream;
boolean running;
public ThreadConnected(BluetoothSocket socket) {
connectedBluetoothSocket = socket;
InputStream in = null;
OutputStream out = null;
running = true;
try {
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connectedInputStream = in;
connectedOutputStream = out;
}
@Override
public void run() {
byte[] buffer = new byte[1048576]; // 20 bits
int bytes;
String strRx = "";
while (running) {
try {
bytes = connectedInputStream.read(buffer);
final String strReceived_freq = new String(buffer,0, bytes/2);
final String strReceived_pxx = new String(buffer,(bytes/2)+1, bytes);
//final int samples_sdr=new Integer(buffer,0,bytes);
final String strByteCnt = String.valueOf(bytes) + " bytes received.\n";
runOnUiThread(new Runnable(){
@Override
public void run() {
Pxx_value.setText(strReceived_pxx+"\n"); // get data PXX
freq_value.setText(strReceived_freq+"\n"); // get data freq
// plot value
/* for (int i=0; i<nb_points; i++)
{
freq[i]=Double.parseDouble(strReceived_freq);
pxx[i]=Double.parseDouble(strReceived_pxx);
series.appendData(new DataPoint(freq[i],pxx[i]), true,500);
}*/
}});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
cancel();
final String msgConnectionLost = "Connection lost:\n" + e.getMessage();
runOnUiThread(new Runnable(){
@Override
public void run() {
}});
}
}
}
public void write(byte[] buffer) {
try {
connectedOutputStream.write(buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void cancel() {
running = false;
try {
connectedBluetoothSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
感謝您編輯@CodyGray,現在真的更加清晰! – azerty12345678
不客氣!感謝您堅持並更新您的問題以迴應您的反饋。如果每個人都這樣做,事情會變得更加順暢。希望你得到一個很好的答案! –
我只是假設你確定藍牙設備沒有發送多個plackets? – Emax