-
Couldn't load subscription status.
- Fork 5
Hackrf tcp server #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi @ellisgl, |
demos/hackrf_tcp_server/main.cpp
Outdated
| return 1; | ||
| } | ||
|
|
||
| int PORT = config["PORT"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I agree with the appeal of json, it bothers me a bit to bring a 25k LOC library into the repo for just 6 paramaters... maybe they could be environment variables?
Having a single vars.sh like:
PORT=
SAMPLE_RATE=
BITRATE=
AMPLITUDE=
FREQ_DEV
TX_GAIN=so the user can just 'source it': . vars.sh before using the tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll look into that
demos/hackrf_tcp_server/main.cpp
Outdated
| * | ||
| * @return std::vector<double> A vector of doubles representing the FSK modulated signal. | ||
| */ | ||
| std::vector<double> generate_fsk_signal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see this function being used anywhere, please consider using it or removing it entirely.
demos/hackrf_tcp_server/main.cpp
Outdated
| // Define the type of socket address, in this case IPv4 | ||
| address.sin_family = AF_INET; | ||
| // Allow connections from any IP address | ||
| address.sin_addr.s_addr = INADDR_ANY; | ||
| // Set the port number | ||
| address.sin_port = htons(PORT); | ||
|
|
||
| // Bind the socket to the address and port | ||
| if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) { | ||
| perror("bind failed"); | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed the server currently binds to all IPv4 addresses by default.
Since this looks like it's intended as a simple server without built-in authentication, it might be safer to default to localhost only. This would prevent accidental exposure on network interfaces.
Please consider:
- Default to binding localhost (127.0.0.1)
- Add a configuration option so users can explicitly choose to bind to other network interfaces when needed
A BIND_ADDRESS environment variable could work.
demos/hackrf_tcp_server/main.cpp
Outdated
| int capcode = std::stoi(capcode_str); | ||
| int frequency = std::stoi(freq_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a stability issue with the input parsing that might be worth addressing.
The server currently uses std::stoi() to parse capcode and frequency values from network input:
int capcode = std::stoi(capcode_str); // Line 175
int frequency = std::stoi(freq_str); // Line 176Since std::stoi() throws exceptions on invalid input (like non-numeric strings or values outside int range), any malformed data will currently crash the server. This could happen accidentally with corrupted data or if someone sends unexpected input.
Quick test case:
If you connect via nc localhost 16175 and send something like 123|test message|not_a_number, the server will terminate with an unhandled exception.
Possible fix:
We could wrap these conversions in try-catch blocks to handle bad input gracefully:
try {
int capcode = std::stoi(capcode_str);
int frequency = std::stoi(freq_str);
// ... continue processing
} catch (const std::exception& e) {
printf("Skipping invalid input: %s\n", e.what());
close(client_fd);
continue; // Handle next client/input
}This way the server stays running even when it receives unexpected data. What do you think about this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I'm working on breaking things down. I figured having all the stuff just shoved in main is kind of sloppy. I will admit to being lazy and letting the nice AI overlords take one for the team. heh.
|
Hey @geekinsanemx
|
|
Hi guys, @geekinsanemx thanks for polishing @ellisgl’s work and addressing the comments I made =). The only thing that bothered me a bit was that changes were also made to the GNURadio demo. I'm not sure if that was accidental or not, but I would have preferred that to be in a separate PR if possible. Still, I can go ahead and merge this as-is, excluding those changes. @rlaneth any additional thoughts on this PR? It looks good to me now. |
|
Hi @Theldus !! ohhh yeap, that's because when I tested with my hackrf find out that I'm using osmosdr_sink, don't know why soapy_hackrf_sink does not work for me, tried to configure hackrf=0 as device argument but unable to send message, I though was more like a simulated sink, that's why changed for osmosdr_sink to actually be able to transmit messages reverting back file to original and adding osmosdr_sink too :) if you exclude those gnuradio changes at merging this, I can open a new PR for adding the osmosdr_sink if you wish! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi everyone,
I agree that modifying hackrf_file_tx_demo.grc is probably not in the scope of this PR. There's a few concerns that have been raised about this flowchart by other users (as in Issue #7), so it might be due to changes in the near future anyway.
As for the TCP server itself, I see no more issues! I have also tested basic functionality with my own HackRF and pagers, and it works flawlessly.
LGTM
reverting back soapy_hackrf_sink, but adding osmosdr_sink
|
Thank you guys for the excellent work, merged in 702f14d. |


Figured a C/C++ TCP server that works with Hackrf would be nice.