Skip to content

Commit

Permalink
Add initial support for using wfb_rx as shared library for android
Browse files Browse the repository at this point in the history
  • Loading branch information
svpcom committed Apr 25, 2024
1 parent 8b73387 commit ecfdfae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
22 changes: 9 additions & 13 deletions src/rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <unistd.h>
#include <time.h>
#include <sys/resource.h>
#include <pcap/pcap.h>
#include <pcap.h>
#include <poll.h>
#include <sys/socket.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -213,10 +213,10 @@ void Receiver::loop_iter(void)


Aggregator::Aggregator(const string &client_addr, int client_port, const string &keypair, uint64_t epoch, uint32_t channel_id) : \
fec_p(NULL), fec_k(-1), fec_n(-1), seq(0), rx_ring_front(0), rx_ring_alloc(0),
last_known_block((uint64_t)-1), epoch(epoch), channel_id(channel_id),
count_p_all(0), count_p_dec_err(0), count_p_dec_ok(0), count_p_fec_recovered(0),
count_p_lost(0), count_p_bad(0), count_p_override(0), count_p_outgoing(0)
count_p_lost(0), count_p_bad(0), count_p_override(0), count_p_outgoing(0),
fec_p(NULL), fec_k(-1), fec_n(-1), seq(0), rx_ring_front(0), rx_ring_alloc(0),
last_known_block((uint64_t)-1), epoch(epoch), channel_id(channel_id)
{
sockfd = open_udp_socket_for_tx(client_addr, client_port);
memset(session_key, '\0', sizeof(session_key));
Expand Down Expand Up @@ -419,7 +419,6 @@ void Aggregator::dump_stats(FILE *fp)
it->second.rssi_min, it->second.rssi_sum / it->second.count_all, it->second.rssi_max,
it->second.snr_min, it->second.snr_sum / it->second.count_all, it->second.snr_max);
}
antenna_stat.clear();

fprintf(fp, "%" PRIu64 "\tPKT\t%u:%u:%u:%u:%u:%u:%u\n", ts, count_p_all, count_p_dec_err, count_p_dec_ok, count_p_fec_recovered, count_p_lost, count_p_bad, count_p_outgoing);
fflush(fp);
Expand All @@ -434,14 +433,7 @@ void Aggregator::dump_stats(FILE *fp)
fprintf(stderr, "%u packets lost\n", count_p_lost);
}

count_p_all = 0;
count_p_dec_err = 0;
count_p_dec_ok = 0;
count_p_fec_recovered = 0;
count_p_lost = 0;
count_p_bad = 0;
count_p_override = 0;
count_p_outgoing = 0;
clear_stats();
}


Expand Down Expand Up @@ -897,6 +889,8 @@ void network_loop(int srv_port, Aggregator &agg, int log_interval, int rcv_buf_s
}
}

#ifndef __WFB_RX_SHARED_LIBRARY__

int main(int argc, char* const *argv)
{
int opt;
Expand Down Expand Up @@ -1009,3 +1003,5 @@ int main(int argc, char* const *argv)
}
return 0;
}

#endif
35 changes: 25 additions & 10 deletions src/rx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ class Aggregator : public BaseAggregator
~Aggregator();
virtual void process_packet(const uint8_t *buf, size_t size, uint8_t wlan_idx, const uint8_t *antenna, const int8_t *rssi, const int8_t *noise, uint16_t freq, sockaddr_in *sockaddr);
virtual void dump_stats(FILE *fp);

// Make stats public for android userspace receiver
void clear_stats(void)
{
antenna_stat.clear();
count_p_all = 0;
count_p_dec_err = 0;
count_p_dec_ok = 0;
count_p_fec_recovered = 0;
count_p_lost = 0;
count_p_bad = 0;
count_p_override = 0;
count_p_outgoing = 0;
}

rx_antenna_stat_t antenna_stat;
uint32_t count_p_all;
uint32_t count_p_dec_err;
uint32_t count_p_dec_ok;
uint32_t count_p_fec_recovered;
uint32_t count_p_lost;
uint32_t count_p_bad;
uint32_t count_p_override;
uint32_t count_p_outgoing;

private:
void init_fec(int k, int n);
void deinit_fec(void);
Expand All @@ -180,16 +205,6 @@ class Aggregator : public BaseAggregator
uint8_t rx_secretkey[crypto_box_SECRETKEYBYTES];
uint8_t tx_publickey[crypto_box_PUBLICKEYBYTES];
uint8_t session_key[crypto_aead_chacha20poly1305_KEYBYTES];

rx_antenna_stat_t antenna_stat;
uint32_t count_p_all;
uint32_t count_p_dec_err;
uint32_t count_p_dec_ok;
uint32_t count_p_fec_recovered;
uint32_t count_p_lost;
uint32_t count_p_bad;
uint32_t count_p_override;
uint32_t count_p_outgoing;
};

class Receiver
Expand Down
2 changes: 1 addition & 1 deletion src/tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ RawSocketTransmitter::RawSocketTransmitter(int k, int n, const string &keypair,
sll.sll_ifindex = ifr.ifr_ifindex;
sll.sll_protocol = 0;

if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0)
if (::bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0)
{
close(fd);
throw runtime_error(string_format("Unable to bind to %s: %s", it->c_str(), strerror(errno)));
Expand Down
2 changes: 1 addition & 1 deletion src/wifibroadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int open_udp_socket_for_rx(int port, int rcv_buf_size)
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = htons((unsigned short)port);

if (bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0)
if (::bind(fd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0)
{
throw runtime_error(string_format("Bind error: %s", strerror(errno)));
}
Expand Down

0 comments on commit ecfdfae

Please sign in to comment.