<commit_before>#include <stdbool.h>
#include <stdio.h>

#include <button.h>
#include <timer.h>

#include <ieee802154.h>
#include <udp.h>

static unsigned char BUF_BIND_CFG[2 * sizeof(sock_addr_t)];
static bool button_press;

void print_ipv6(ipv6_addr_t *);

void print_ipv6(ipv6_addr_t *ipv6_addr) {
  for (int j = 0; j < 14; j += 2) {
    printf("%02x%02x:", ipv6_addr->addr[j], ipv6_addr->addr[j + 1]);
  }
  printf("%02x%02x", ipv6_addr->addr[14], ipv6_addr->addr[15]);
}

static void button_callback(__attribute__ ((unused)) int btn_num,
                            int val,
                            __attribute__ ((unused)) int arg2,
                            __attribute__ ((unused)) void *ud) {
  if (val == 1) {
    button_press = true;
  }
}

int main(void) {

  button_subscribe(button_callback, NULL);
  int count = button_count();
  for (int i = 0; i < count; i++) {
    button_enable_interrupt(i);
  }

  char packet[64];
  button_press = false;

  ieee802154_set_pan(0xABCD);
  ieee802154_config_commit();
  ieee802154_up();

  ipv6_addr_t ifaces[10];
  udp_list_ifaces(ifaces, 10);

  sock_handle_t handle;
  sock_addr_t addr = {
    ifaces[2],
    15123
  };

  printf("Opening socket on ");
  print_ipv6(&ifaces[2]);
  printf(" : %d\n", addr.port);
  int bind_return = udp_bind(&handle, &addr, BUF_BIND_CFG);
  if (bind_return < 0) {
    printf("Bind failed. Error code: %d\n", bind_return);
    return -1;
  }

  // Set the below address to IP address of receiver
  ipv6_addr_t dest_addr = {
    {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0xbf, 0xf0}
  };
  sock_addr_t destination = {
    dest_addr,
    16123
  };

  int len = snprintf(packet, sizeof(packet), "A button was pressed!\n");

  while (1) {
    // wait for gpio pin to be pressed
    while (!button_press) {
      delay_ms(1);
    }
    button_press = false;

    printf("Button press detected\n");

    printf("Sending packet (length %d) --> ", len);
    print_ipv6(&(destination.addr));
    printf(" : %d\n", destination.port);
    ssize_t result = udp_send_to(packet, len, &destination);

    switch (result) {
      case TOCK_SUCCESS:
        printf("Packet sent.\n");
        break;
      case TOCK_ENOACK:
        printf("Sent but not acknowledged\n");
        break;
      default:
        printf("Error sending packet %d\n", result);
    }
  }
}<commit_msg>removed delay_ms from loop<commit_after>#include <stdbool.h>
#include <stdio.h>

#include <button.h>

#include <ieee802154.h>
#include <udp.h>

static unsigned char BUF_BIND_CFG[2 * sizeof(sock_addr_t)];
static int button_press;

void print_ipv6(ipv6_addr_t *);

void print_ipv6(ipv6_addr_t *ipv6_addr) {
  for (int j = 0; j < 14; j += 2) {
    printf("%02x%02x:", ipv6_addr->addr[j], ipv6_addr->addr[j + 1]);
  }
  printf("%02x%02x", ipv6_addr->addr[14], ipv6_addr->addr[15]);
}

int main(void) {

  char packet[64];
  button_press = 0;

  ieee802154_set_pan(0xABCD);
  ieee802154_config_commit();
  ieee802154_up();

  ipv6_addr_t ifaces[10];
  udp_list_ifaces(ifaces, 10);

  sock_handle_t handle;
  sock_addr_t addr = {
    ifaces[2],
    15123
  };

  printf("Opening socket on ");
  print_ipv6(&ifaces[2]);
  printf(" : %d\n", addr.port);
  int bind_return = udp_bind(&handle, &addr, BUF_BIND_CFG);
  if (bind_return < 0) {
    printf("Bind failed. Error code: %d\n", bind_return);
    return -1;
  }

  // Set the below address to IP address of receiver
  ipv6_addr_t dest_addr = {
    {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0xbf, 0xf0}
  };
  sock_addr_t destination = {
    dest_addr,
    16123
  };

  int len = snprintf(packet, sizeof(packet), "A button was pressed!\n");

  while (1) {
    // wait for gpio pin to be pressed
    while (button_press == 0) {
      button_press = button_read(0);
    }

    printf("Button press detected\n");

    printf("Sending packet (length %d) --> ", len);
    print_ipv6(&(destination.addr));
    printf(" : %d\n", destination.port);
    ssize_t result = udp_send_to(packet, len, &destination);

    switch (result) {
      case TOCK_SUCCESS:
        printf("Packet sent.\n");
        break;
      case TOCK_ENOACK:
        printf("Sent but not acknowledged\n");
        break;
      default:
        printf("Error sending packet %d\n", result);
    }

    // Debounce
    while (button_press != 0) {
      button_press = button_read(0);
    }
  }
}
{'fraction_non_alphanumeric': 0.14824120603015076, 'fraction_numerical': 0.0459113750571037, 'mean_word_length': 3.0211202938475665, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '4490322', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1670, 'n_words': 385}