Last active
April 15, 2024 11:27
-
-
Save sp5wwp/c53602549f8ccde0c6e30d593aa6bb5b to your computer and use it in GitHub Desktop.
ZeroMQ baseband publisher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
to source IQ baseband samples from SX1255 over I2S, run this: | |
arecord -t raw -f S32_LE -r 192000 -c 2 --device="hw:0,1" | ./zmq-pub | |
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_downlink; | |
int rcvd; | |
uint8_t inp[100000]; | |
int main(void) | |
{ | |
zmq_ctx = zmq_ctx_new(); | |
bsb_downlink = zmq_socket(zmq_ctx, ZMQ_PUB); | |
printf("ZeroMQ "); | |
if(zmq_bind(bsb_downlink, "tcp://*:17017")==0) | |
printf("OK\n"); | |
else | |
printf("ERROR\n"); | |
while(1) | |
{ | |
ioctl(STDIN_FILENO, FIONREAD, &rcvd); | |
if(rcvd>0) | |
{ | |
if(read(STDIN_FILENO, inp, rcvd)==rcvd) | |
{ | |
#if defined(SAMP_INT32) //signed 32-bit ints | |
zmq_send(bsb_downlink, (char*)inp, rcvd, 0); | |
#elif defined(SAMP_FLOAT) //32-bit floats | |
float val[100000]; | |
memset(val, 0, sizeof(val)); | |
for(int j=0; j<rcvd; j+=8) | |
{ | |
int32_t i=0, q=0; | |
memcpy((uint8_t*)&i, &inp[0+j], 4); | |
memcpy((uint8_t*)&q, &inp[4+j], 4); | |
val[(j/8)*2] =i/(float)0x7FFFFFFFL; | |
val[(j/8)*2+1]=q/(float)0x7FFFFFFFL; | |
} | |
zmq_send(bsb_downlink, (char*)val, rcvd, 0); | |
#endif | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment