UDP Socket
Send data to UDP Socket.
class UDPSocket {
constructor UDPSocket(String deshost, int destport);
bool sendIQ( IQData iq ); // send IQ to UDP
bool sendBytes( Array );
bool sendString( txt );
close();
}
Constructor
- Object: UDPSocket('name')
var p = new UDPSocket('test');
.sendString
Send string (text object).
.sendString(txt);
// run 'nc -ul 8888' in bash
var s = new UDPSocket('127.0.0.1',8888);
if( s.sendString('Hello world') == false ) {
printf('Udp Error');
exit();
}
.sendBytes
Send bytes (Uint8Array object)
.sendBytes(bytes);
- Example
// run 'nc -ul 8888' in bash
var s = new UDPSocket('127.0.0.1',8888);
// sendString
if( s.sendString('OneTwoThee') == false ) {
printf('Udp Error');
exit();
}
// sendBytes
var buff = new Array();
for( var ascii=48 ; ascii < 68 ; ascii++ )
buff.push( ascii );
s.sendBytes( buff );
s.close();
.sendIQ
Send IQ blocks
.sendIQ( IQBlock, channel, IQFormat);
Available fields are :
- IQBlock : IQ object to send
- Channel : 0 (RXA), or 1(RXB)
-
IQFormat :
- 0 : CF32
- 1 : CS16
-
Basic example
// run 'nc -ul 8888' in bash
var s = new UDPSocket('127.0.0.1',8888);
var iq = DSP.tone(440, 80000, 48e3);
s.sendIQ(iq,0,1);
- Example
// open and tune RF input
var rx = Soapy.makeDevice({'query' : 'driver=sdrplay' }) ;
rx.setRxCenterFreq(465.5);
rx.setRxSampleRate(2e6);
rx.setGain( 10 ) ;
// engage streaming
var fifo_from_rx = Queues.create( 'input');
if( !fifo_from_rx.ReadFromRx( rx ) ) {
print('Cannot stream from rx');
exit();
}
// Prepare UDP
var s = new UDPSocket('0.0.0.0',8888);
if( s.sendString('OneTwoThee') == false ) {
printf('Udp Error');
exit();
}
var IQBlock = new IQData('iq');
print('starting rx process');
while( fifo_from_rx.isFromRx() ) {
if( IQBlock.readFromQueue( fifo_from_rx ) ) {
//IQBlock.dump();
// s.sendIQ( IQBlock,0,1 ); //CS16
s.sendIQ( IQBlock,0,0 ); //CF32
}
}
}
.close
Close the active connection
.close();
Last update: August 22, 2023