Exemplo n.º 1
0
void sync_debug_msg_get_all( uint16_t* local_timer, uint16_t* remote_timer, 
      int16_t* remote_offset, uint8_t* remote_id )
{
  sync_debug_msg_t* p_packet_data = (sync_debug_msg_t*)p_in_buffer;
  *local_timer = endian_swap16( p_packet_data->local_timer );
  *remote_timer = endian_swap16( p_packet_data->remote_timer );
  *remote_offset = endian_swap16( p_packet_data->remote_offset );
  *remote_id = p_packet_data->remote_id;
  return;
}
Exemplo n.º 2
0
uint16_t adc_stream_msg_get_packet_number()
{
  test_adc_stream_numbered_msg_t* p_packet_data = 
    (test_adc_stream_numbered_msg_t*)p_in_buffer;
    
  return endian_swap16( p_packet_data->packet_number );
}
Exemplo n.º 3
0
uint16_t serial_msg_get_counter1()
{
  // Make sure the message in buffer is of correct type, otherwise return 0
  if( AM_SERIAL_MSG == in_packet.am_type )
  {
    test_serial_msg_t* p_packet_data = (test_serial_msg_t*)p_in_buffer;
    return endian_swap16( p_packet_data->counter1 );
  }
  return 0;
}
Exemplo n.º 4
0
uint16_t serial_adc_msg_get_channel( uint8_t channel )
{
  // Make sure the message in buffer is of correct type, otherwise return 0
  if( (AM_ADC_SERIAL_MSG == in_packet.am_type) && ( channel < ADC_CHANNELS )  )
  {
    test_adc_serial_msg_t* p_packet_data = (test_adc_serial_msg_t*)p_in_buffer;
    
    return endian_swap16( p_packet_data->channels[channel] );
  }
  return 0;
}
Exemplo n.º 5
0
int ubertooth_u1_poll(spectool_phy *phydev) {
	ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr;
	char lbuf[64];
	int x, freq, ret, full = 0, rssi;
	ubertooth_u1_report *report = (ubertooth_u1_report *) lbuf;

	/* Push a configure event before anything else */
	if (auxptr->configured == 0) {
		auxptr->configured = 1;
		return SPECTOOL_POLL_CONFIGURED;
	}

	/* Use the error set by the polling thread */
	if (auxptr->usb_thread_alive == 0) {
		phydev->state = SPECTOOL_STATE_ERROR;
		ubertooth_u1_close(phydev);
		return SPECTOOL_POLL_ERROR;
	}

	if ((ret = recv(auxptr->sockpair[0], lbuf, 64, 0)) < 0) {
		if (auxptr->usb_thread_alive != 0)
			snprintf(phydev->errstr, SPECTOOL_ERROR_MAX,
					 "ubertooth_u1 IPC receiver failed to read signal data: %s",
					 strerror(errno));
		phydev->state = SPECTOOL_STATE_ERROR;
		return SPECTOOL_POLL_ERROR;
	}

	if (time(0) - auxptr->last_read > 3) {
		snprintf(phydev->errstr, SPECTOOL_ERROR_MAX,
				 "ubertooth_u1 didn't see any data for more than 3 seconds, "
				 "something has gone wrong (was the device removed?)");
		phydev->state = SPECTOOL_STATE_ERROR;
		return SPECTOOL_POLL_ERROR;
	}

	if (ret > 0)
		auxptr->last_read = time(0);

	// If we don't have a sweepbuf we're not configured, barf
	if (auxptr->sweepbuf == NULL) {
		return SPECTOOL_POLL_NONE;
	}

	// If we're full entering a read we need to wipe out
	if (auxptr->peak_cache->num_used >= UBERTOOTH_U1_AVG_SAMPLES) {
		// spectool_cache_clear(auxptr->peak_cache);
		// printf("debug - clearing peak cache\n");
	}

	for (x = 0; x < 16; x++) {
		// printf("%u %d\n", endian_swap16(report->data[x].be_freq), report->data[x].rssi);
#ifdef WORDS_BIGENDIAN
		freq = report->data[x].be_freq;
#else
		freq = endian_swap16(report->data[x].be_freq);
#endif

		freq = freq - (auxptr->sweepbuf->start_khz / 1000);

		rssi = (report->data[x].rssi + 55);

		// printf("%u = %d ", freq, rssi);

		if (freq < 0 || freq >= auxptr->sweepbuf->num_samples) {
			printf("debug - sample freq %d not in range\n", freq);
			continue;
		}

		auxptr->sweepbuf->sample_data[freq] = rssi;

		if (rssi < phydev->min_rssi_seen)
			phydev->min_rssi_seen = rssi;

		if (freq == 0) {
			if (auxptr->primed == 0) {
				// printf("debug - u1 primed\n");
				auxptr->primed = 1;
				continue;
			}

			auxptr->sweepbuf_initialized = 1;
			auxptr->num_sweeps++;

			gettimeofday(&(auxptr->sweepbuf->tm_end), NULL);
			auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen;

			/*
			if (auxptr->full_sweepbuf != NULL) {
				free(auxptr->full_sweepbuf);
			}

			auxptr->full_sweepbuf = auxptr->sweepbuf;
			*/

			// auxptr->sweepbuf = ubertooth_u1_build_sweepbuf(phydev);

			spectool_cache_append(auxptr->peak_cache, auxptr->sweepbuf);

			if (auxptr->peak_cache->num_used >= UBERTOOTH_U1_AVG_SAMPLES) {
				full = 1;
			}

			gettimeofday(&(auxptr->sweepbuf->tm_start), NULL);

			// printf("debug - u1 - sweep complete, freq %d\n", freq);
		}
	}

	if (full == 1) {
		// printf("debug - returning sc\n");
		return SPECTOOL_POLL_SWEEPCOMPLETE;
	}


#if 0
	/*

	/* Initialize the sweep buffer when we get to it 
	 * If we haven't gotten around to a 0 state to initialize the buffer, we throw
	 * out the sample data until we do. */
	if (base == 0) {
		auxptr->sweepbuf_initialized = 1;
		auxptr->num_sweeps++;

		/* Init the timestamp for sweep begin */
		gettimeofday(&(auxptr->sweepbuf->tm_start), NULL);
	} else if (auxptr->sweepbuf_initialized == 0) {
		return SPECTOOL_POLL_NONE;
	}

	for (x = 0; x < report->valid_bytes; x++) {
		if (base + x >= auxptr->sweepbuf->num_samples) {
			break;
		}

		/*
		auxptr->sweepbuf->sample_data[base + x] =
			ubertooth_u1_RSSI(report->data[x]);
		*/
		auxptr->sweepbuf->sample_data[base + x] = report->data[x];

		if (report->data[x] < phydev->min_rssi_seen)
			phydev->min_rssi_seen = report->data[x];
	}

	auxptr->sweepbase += report->valid_bytes;

	/* Flag that a sweep is complete */
	if (base + report->valid_bytes == auxptr->sweepbuf->num_samples) {
		gettimeofday(&(auxptr->sweepbuf->tm_end), NULL);
		auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen;
		return SPECTOOL_POLL_SWEEPCOMPLETE;
	}
#endif

	return SPECTOOL_POLL_NONE;
}