示例#1
0
文件: main.c 项目: mjftw/CubeSat
float time_function()
{
  time_t now = time(NULL);
  unsigned int runs = 0;
  unsigned int time_length = 5;  //seconds
  while(time(NULL) == now);
  now++;
  int t = 2;

  //setup for funciton here
  raw_data rd;
  rd.length = 64;
  rd.data = (uint8_t*)alloc_named(rd.length, "time_function rd.data");

  raw_data rd2 = packet_data(rd, t, 4);
  insert_errors2(rd2.data, rd2.length, 0.1442);
  raw_data rd3;

  while(time(NULL) - time_length < now)
  {
    unpacket_data(rd2, &rd3, t, 4, NULL);
    dealloc(rd3.data);
    runs++;
  }

  //setdown for function here
  dealloc(rd.data);

  return (float)runs / (float)time_length;
}
示例#2
0
文件: net.c 项目: bengal/nsdpc
int net_send_packet(int sock, struct packet *packet)
{
	struct sockaddr_in addr;

	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = INADDR_BROADCAST;
	addr.sin_port = htons(63322);

	return sendto(sock, packet_data(packet), packet_len(packet), 0,
		      (struct sockaddr *)&addr, sizeof(addr));
}
示例#3
0
文件: main.c 项目: mjftw/CubeSat
void test_packeting(unsigned int tries, unsigned int length, float BER, unsigned int rs_t, unsigned int conv_constraint)
{
  //tests packeting code.
  //Also tests for false positives and false negative decoding.
  int correct = 0, incorrect1 = 0, incorrect2 = 0;
  unsigned int i;
  for(i = 0; i < tries; i++)
  {
    raw_data rd;
    rd.length = length;
    rd.data = (uint8_t*)alloc_named(rd.length, "main rd.data");
    unsigned int j;
    for(j = 0; j < rd.length; j++)
      rd.data[j] = rand();

    raw_data packet = packet_data(rd, rs_t, conv_constraint);

    //insert errors here
    insert_errors2(packet.data, packet.length, BER);

    raw_data received;
    if(unpacket_data(packet, &received, rs_t, conv_constraint, NULL))
    {
      if(!memcmp(received.data, rd.data, rd.length))
        correct++;
      else
        incorrect1++;
    }
    else
    {
      if(memcmp(received.data, rd.data, rd.length))
        correct++;
      else
      {
        incorrect2++;
      }
    }

    dealloc(rd.data);
    dealloc(packet.data);
    dealloc(received.data);
  }
  printf("correct = %i\n", correct);
  printf("false positives = %i\n", incorrect1);
  printf("false negatives = %i\n", incorrect2);
}
示例#4
0
文件: main.c 项目: mjftw/CubeSat
float coding_gain(float SNR, int t, int tests)
{
  table_t snr_ber = read_snr_ber();
  float BER = table_lookup(&snr_ber, SNR);
  printf("channel BER = %f\n", BER);

  unsigned int errors = 0;
  unsigned int i;
  for(i = 0; i < tests; i++)
  {
    raw_data rd;
    rd.length = 64;
    rd.data = (uint8_t*)alloc_named(rd.length, "message_pass_rate rd");
    unsigned int j;
    for(j = 0; j < 64; j++)
      rd.data[j] = rand();

    raw_data encoded_packet = packet_data(rd, t, 16);
    insert_errors2(encoded_packet.data, encoded_packet.length, BER);
    raw_data decoded_packet;
    unpacket_data(encoded_packet, &decoded_packet, t, 16, NULL);

    for(j = 0; j < rd.length; j++)
    {
      uint8_t tmp = rd.data[j] ^ decoded_packet.data[j];
      unsigned int k;
      for(k = 0; k < 8; k++)
      {
        if(1 << k & tmp)
          errors++;
      }
    }
  }
  printf("new BER = %f\n", (float)errors / (float)(64 * 8 * tests));
  return reverse_table_lookup(&snr_ber, (float)errors / (float)(64 * 8 * tests)) - SNR;
}