<commit_before>#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <poll.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

uint32_t *rx_freq[2], *rx_rate[2], *tx_freq;
uint16_t *gpio, *rx_cntr[2], *tx_cntr;
void *rx_data[2], *tx_data;

const uint32_t freq_min = 0;
const uint32_t freq_max = 61440000;

int receivers = 1;

int sock_ep2;
struct sockaddr_in addr_ep6;
socklen_t size_ep6;

int enable_thread = 0;
int active_thread = 0;

void process_ep2(char *frame);
void *handler_ep6(void *arg);

int main(int argc, char *argv[])
{
  int fd;
  pthread_t thread;
  void *cfg[2], *sts[2];
  char *end, *name = "/dev/mem";
  char buffer[1032];
  uint8_t reply[11] = {0xef, 0xfe, 2, 0, 0, 0, 0, 0, 0, 18, 0};
  struct sockaddr_in addr_ep2;
  socklen_t size_ep2;
  ssize_t result;
  int i, yes = 1;

  if((fd = open(name, O_RDWR)) < 0)
  {
    perror("open");
    return EXIT_FAILURE;
  }

  cfg[0] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40000000);
  sts[0] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);
  rx_data[0] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40002000);
  tx_data = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40004000);
  cfg[1] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40006000);
  sts[1] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40007000);
  rx_data[1] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40008000);

  gpio = ((uint16_t *)(cfg + 0));

  rx_freq[0] = ((uint32_t *)(cfg[0] + 4));
  rx_rate[0] = ((uint32_t *)(cfg[0] + 8));
  rx_cntr[0] = ((uint16_t *)(sts[0] + 0));

  tx_freq = ((uint32_t *)(cfg[0] + 12));
  tx_cntr = ((uint16_t *)(sts[0] + 2));

  rx_freq[1] = ((uint32_t *)(cfg[1] + 0));
  rx_rate[1] = ((uint32_t *)(cfg[1] + 4));
  rx_cntr[1] = ((uint16_t *)(sts[1] + 0));

  /* set PTT pin to low */
  *gpio = 0;

  /* set default rx phase increment */
  *rx_freq[0] = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);
  *rx_freq[1] = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);
  /* set default rx sample rate */
  *rx_rate[0] = 1000;
  *rx_rate[1] = 1000;

  /* set default tx phase increment */
  *tx_freq = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);

  if((sock_ep2 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  {
    perror("socket");
    return EXIT_FAILURE;
  }

  setsockopt(sock_ep2, SOL_SOCKET, SO_REUSEADDR, (void *)&yes , sizeof(yes));

  memset(&addr_ep2, 0, sizeof(addr_ep2));
  addr_ep2.sin_family = AF_INET;
  addr_ep2.sin_addr.s_addr = htonl(INADDR_ANY);
  addr_ep2.sin_port = htons(1024);
  size_ep2 = sizeof(addr_ep2);

  if(bind(sock_ep2, (struct sockaddr *)&addr_ep2, sizeof(addr_ep2)) < 0)
  {
    perror("bind");
    return EXIT_FAILURE;
  }

  while(1)
  {
    result = recvfrom(sock_ep2, buffer, 1032, 0, (struct sockaddr *)&addr_ep6, &size_ep6);
    if(result <= 0) break;

    printf("read %08x\n", *(uint32_t *)buffer);

    switch(*(uint32_t *)buffer)
    {
      case 0x0201feef:
        process_ep2(buffer + 11);
        process_ep2(buffer + 523);
        break;
      case 0x0002feef:
        reply[2] = 2 + active_thread;
        memset(buffer, 0, 60);
        memcpy(buffer, reply, 11);
        sendto(sock_ep2, buffer, 60, 0, (struct sockaddr *)&addr_ep6, size_ep6);
        break;
      case 0x0004feef:
        enable_thread = 0;
        while(active_thread)
        {
          usleep(1000);
        }
        break;
      case 0x0104feef:
      case 0x0204feef:
      case 0x0304feef:
        if(!active_thread)
        {
          enable_thread = 1;
          active_thread = 1;
          if(pthread_create(&thread, NULL, handler_ep6, NULL) < 0)
          {
            perror("pthread_create");
            return EXIT_FAILURE;
          }
          pthread_detach(thread);
        }
        break;
		}
	}<commit_msg>remove unused variables from sdr-transceiver-hpsdr.c<commit_after>#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <poll.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

uint32_t *rx_freq[2], *rx_rate[2], *tx_freq;
uint16_t *gpio, *rx_cntr[2], *tx_cntr;
void *rx_data[2], *tx_data;

const uint32_t freq_min = 0;
const uint32_t freq_max = 61440000;

int receivers = 1;

int sock_ep2;
struct sockaddr_in addr_ep6;
socklen_t size_ep6;

int enable_thread = 0;
int active_thread = 0;

void process_ep2(char *frame);
void *handler_ep6(void *arg);

int main(int argc, char *argv[])
{
  int fd;
  pthread_t thread;
  void *cfg[2], *sts[2];
  char *name = "/dev/mem";
  char buffer[1032];
  uint8_t reply[11] = {0xef, 0xfe, 2, 0, 0, 0, 0, 0, 0, 18, 0};
  struct sockaddr_in addr_ep2;
  ssize_t result;
  int yes = 1;

  if((fd = open(name, O_RDWR)) < 0)
  {
    perror("open");
    return EXIT_FAILURE;
  }

  cfg[0] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40000000);
  sts[0] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40001000);
  rx_data[0] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40002000);
  tx_data = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40004000);
  cfg[1] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40006000);
  sts[1] = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40007000);
  rx_data[1] = mmap(NULL, 2*sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x40008000);

  gpio = ((uint16_t *)(cfg + 0));

  rx_freq[0] = ((uint32_t *)(cfg[0] + 4));
  rx_rate[0] = ((uint32_t *)(cfg[0] + 8));
  rx_cntr[0] = ((uint16_t *)(sts[0] + 0));

  tx_freq = ((uint32_t *)(cfg[0] + 12));
  tx_cntr = ((uint16_t *)(sts[0] + 2));

  rx_freq[1] = ((uint32_t *)(cfg[1] + 0));
  rx_rate[1] = ((uint32_t *)(cfg[1] + 4));
  rx_cntr[1] = ((uint16_t *)(sts[1] + 0));

  /* set PTT pin to low */
  *gpio = 0;

  /* set default rx phase increment */
  *rx_freq[0] = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);
  *rx_freq[1] = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);
  /* set default rx sample rate */
  *rx_rate[0] = 1000;
  *rx_rate[1] = 1000;

  /* set default tx phase increment */
  *tx_freq = (uint32_t)floor(600000/125.0e6*(1<<30)+0.5);

  if((sock_ep2 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  {
    perror("socket");
    return EXIT_FAILURE;
  }

  setsockopt(sock_ep2, SOL_SOCKET, SO_REUSEADDR, (void *)&yes , sizeof(yes));

  memset(&addr_ep2, 0, sizeof(addr_ep2));
  addr_ep2.sin_family = AF_INET;
  addr_ep2.sin_addr.s_addr = htonl(INADDR_ANY);
  addr_ep2.sin_port = htons(1024);

  if(bind(sock_ep2, (struct sockaddr *)&addr_ep2, sizeof(addr_ep2)) < 0)
  {
    perror("bind");
    return EXIT_FAILURE;
  }

  while(1)
  {
    result = recvfrom(sock_ep2, buffer, 1032, 0, (struct sockaddr *)&addr_ep6, &size_ep6);
    if(result <= 0) break;

    printf("read %08x\n", *(uint32_t *)buffer);

    switch(*(uint32_t *)buffer)
    {
      case 0x0201feef:
        process_ep2(buffer + 11);
        process_ep2(buffer + 523);
        break;
      case 0x0002feef:
        reply[2] = 2 + active_thread;
        memset(buffer, 0, 60);
        memcpy(buffer, reply, 11);
        sendto(sock_ep2, buffer, 60, 0, (struct sockaddr *)&addr_ep6, size_ep6);
        break;
      case 0x0004feef:
        enable_thread = 0;
        while(active_thread)
        {
          usleep(1000);
        }
        break;
      case 0x0104feef:
      case 0x0204feef:
      case 0x0304feef:
        if(!active_thread)
        {
          enable_thread = 1;
          active_thread = 1;
          if(pthread_create(&thread, NULL, handler_ep6, NULL) < 0)
          {
            perror("pthread_create");
            return EXIT_FAILURE;
          }
          pthread_detach(thread);
        }
        break;
    }
  }
{'fraction_non_alphanumeric': 0.1653304178814383, 'fraction_numerical': 0.07981049562682216, 'mean_word_length': 3.508762322015334, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3314005', 'n_tokens_mistral': 3984, 'n_tokens_neox': 3525, 'n_words': 688}