Skip to content

Instantly share code, notes, and snippets.

@sp5wwp
Last active May 19, 2024 18:07
Show Gist options
  • Save sp5wwp/2df5b794c793be340941681a36e59918 to your computer and use it in GitHub Desktop.
Save sp5wwp/2df5b794c793be340941681a36e59918 to your computer and use it in GitHub Desktop.
ZeroMQ baseband subscriber
/*
to pass IQ baseband samples to SX1255 over I2S, run this:
./zmq-sub | aplay -t raw -f S32_LE -r 192000 -c 2 --device="hw:0,0"
note: you need to enable I2S overlay (acting as a slave)
this one works good: https://github.com/AkiyukiOkayasu/RaspberryPi_I2S_Slave
note: setting the rate to 192k isn't really effective, the actual rate is 125k (governed by the I2S master - SX1255)
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <zmq.h>
#define SAMP_FLOAT
void *zmq_ctx;
void *bsb_uplink;
int rcvd;
uint8_t inp[100000];
int main(void)
{
zmq_ctx = zmq_ctx_new();
bsb_uplink = zmq_socket(zmq_ctx, ZMQ_SUB);
printf("ZeroMQ ");
if(zmq_connect(bsb_uplink, "tcp://10.10.10.17:17018")==0)
printf("OK\n");
else
printf("ERROR\n");
zmq_setsockopt(bsb_uplink, ZMQ_SUBSCRIBE, "", 0);
while(1)
{
rcvd=zmq_recv(bsb_uplink, inp, sizeof(inp), 0);
if(rcvd!=-1)
{
#if defined(SAMP_INT32)
write(STDOUT_FILENO, inp, rcvd);
#elif defined(SAMP_FLOAT)
int32_t val[15000];
for(int j=0; j<rcvd; j+=8)
{
val[(j/8)*2] =*(float*)&inp[j ]*0x80000000L;
val[(j/8)*2+1]=*(float*)&inp[j+4]*0x80000000L;
}
write(STDOUT_FILENO, (uint8_t*)val, rcvd);
#endif
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment