Пример #1
0
size_t
arv_fake_camera_get_payload (ArvFakeCamera *camera)
{
	guint32 width, height;

	g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), 0);

	width = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_WIDTH);
	height = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_HEIGHT);

	return width * height;
}
Пример #2
0
void
arv_fake_camera_fill_buffer (ArvFakeCamera *camera, ArvBuffer *buffer, guint32 *packet_size)
{
	struct timespec time;
	guint32 width;
	guint32 height;
	guint32 exposure_time_us;
	guint32 gain;
	guint32 pixel_format;
	size_t payload;

	if (camera == NULL || buffer == NULL)
		return;

	clock_gettime (CLOCK_MONOTONIC, &time);

	width = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_WIDTH);
	height = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_HEIGHT);
	payload = width * height;

	if (buffer->priv->size < payload) {
		buffer->priv->status = ARV_BUFFER_STATUS_SIZE_MISMATCH;
		return;
	}

	buffer->priv->gvsp_payload_type = ARV_GVSP_PAYLOAD_TYPE_IMAGE;
	buffer->priv->width = width;
	buffer->priv->height = height;
	buffer->priv->status = ARV_BUFFER_STATUS_SUCCESS;
	buffer->priv->timestamp_ns = ((guint64) time.tv_sec) * 1000000000LL + time.tv_nsec;
	buffer->priv->frame_id = camera->priv->frame_id++;
	buffer->priv->pixel_format = _get_register (camera, ARV_FAKE_CAMERA_REGISTER_PIXEL_FORMAT);

#if GLIB_CHECK_VERSION(2,32,0)
	g_mutex_lock (&camera->priv->fill_pattern_mutex);
#else
	g_mutex_lock (camera->priv->fill_pattern_mutex);
#endif
	arv_fake_camera_read_register (camera, ARV_FAKE_CAMERA_REGISTER_EXPOSURE_TIME_US, &exposure_time_us);
	arv_fake_camera_read_register (camera, ARV_FAKE_CAMERA_REGISTER_GAIN_RAW, &gain);
	arv_fake_camera_read_register (camera, ARV_FAKE_CAMERA_REGISTER_PIXEL_FORMAT, &pixel_format);
	camera->priv->fill_pattern_callback (buffer, camera->priv->fill_pattern_data,
					     exposure_time_us, gain, pixel_format);
#if GLIB_CHECK_VERSION(2,32,0)
	g_mutex_unlock (&camera->priv->fill_pattern_mutex);
#else
	g_mutex_unlock (camera->priv->fill_pattern_mutex);
#endif

	if (packet_size != NULL)
		*packet_size = _get_register (camera, ARV_GVBS_STREAM_CHANNEL_0_PACKET_SIZE_OFFSET);
}
Пример #3
0
guint32
arv_fake_camera_get_acquisition_status (ArvFakeCamera *camera)
{
	g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), 0);

	return _get_register (camera, ARV_FAKE_CAMERA_REGISTER_ACQUISITION);
}
Пример #4
0
// default address for pipe 0 is 0xe7e7e7e7e7
// default address for pipe 1 is 0xc2c2c2c2c2
// default address for pipe 2 is 0xc2c2c2c2c3 (disabled)
// default address for pipe 3 is 0xc2c2c2c2c4 (disabled)
// default address for pipe 4 is 0xc2c2c2c2c5 (disabled)
// default address for pipe 5 is 0xc2c2c2c2c6 (disabled)
void Radio_Configure_Rx(RADIO_PIPE pipe, uint8_t* address, uint8_t enable)
{
	uint8_t value;
	uint8_t use_aa = 1;
	uint8_t payload_width = 32;
	if (payload_width < 1 || payload_width > 32 || pipe < RADIO_PIPE_0 || pipe > RADIO_PIPE_5) return;

	// store the pipe 0 address so that it can be overwritten when transmitting with auto-ack enabled.
	if (pipe == RADIO_PIPE_0)
	{
		rx_pipe0_address[0] = address[0];
		rx_pipe0_address[1] = address[1];
		rx_pipe0_address[2] = address[2];
		rx_pipe0_address[3] = address[3];
		rx_pipe0_address[4] = address[4];
	}

	// Set the address.  We set this stuff even if the pipe is being disabled, because for example the transmitter
	// needs pipe 0 to have the same address as the Tx address for auto-ack to work, even if pipe 0 is disabled.
	_set_register(RX_ADDR_P0 + pipe, address, pipe > RADIO_PIPE_1 ? 1 : ADDRESS_LENGTH);

	// Set auto-ack.
	_get_register(EN_AA, &value, 1);
	if (use_aa)
		value |= _BV(pipe);
	else
		value &= ~_BV(pipe);

	_set_register(EN_AA, &value, 1);

	// Set the pipe's payload width.  If the pipe is being disabled, then the payload width is set to 0.
	value = enable ? payload_width : 0;
	_set_register(RX_PW_P0 + pipe, &value, 1);
	rx_pipe_widths[pipe] = value;

	// Enable or disable the pipe.
	_get_register(EN_RXADDR, &value, 1);
	if (enable)
		value |= _BV(pipe);
	else
		value &= ~_BV(pipe);
	_set_register(EN_RXADDR, &value, 1);
}
Пример #5
0
GSocketAddress *
arv_fake_camera_get_stream_address (ArvFakeCamera *camera)
{
	GSocketAddress *stream_socket_address;
	GInetAddress *inet_address;
	guint32 value;

	g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), NULL);

	value = GUINT32_FROM_BE (_get_register (camera, ARV_GVBS_STREAM_CHANNEL_0_IP_ADDRESS_OFFSET));

	inet_address = g_inet_address_new_from_bytes ((guint8 *) &value, G_SOCKET_FAMILY_IPV4);
	stream_socket_address = g_inet_socket_address_new
		(inet_address,
		 _get_register (camera, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET));
	g_object_unref (inet_address);

	return stream_socket_address;
}
Пример #6
0
void _set_rx_mode()
{
	uint8_t config;
	_get_register(CONFIG, &config, 1);
	if ((config & _BV(PRIM_RX)) == 0)
	{
		config |= _BV(PRIM_RX);
		_set_register(CONFIG, &config, 1);
		// the radio takes 130 us to power up the receiver.
		_delay_us(65);
		_delay_us(65);
	}
}
Пример #7
0
void
arv_fake_camera_wait_for_next_frame (ArvFakeCamera *camera)
{
	struct timespec time;
	struct timespec sleep_time;
	guint64 sleep_time_ns;
	guint64 frame_period_time_ns;

	if (_get_register (camera, ARV_FAKE_CAMERA_REGISTER_TRIGGER_MODE) == 1)
		frame_period_time_ns = 1000000000L / camera->priv->trigger_frequency;
	else
		frame_period_time_ns = (guint64) _get_register (camera,
								ARV_FAKE_CAMERA_REGISTER_ACQUISITION_FRAME_PERIOD_US) *
			1000L;

	clock_gettime (CLOCK_MONOTONIC, &time);
	sleep_time_ns = frame_period_time_ns - (((guint64) time.tv_sec * 1000000000L +
						 (guint64) time.tv_nsec) % frame_period_time_ns);

	sleep_time.tv_sec = sleep_time_ns / 1000000000L;
	sleep_time.tv_nsec = sleep_time_ns % 1000000000L;

	nanosleep (&sleep_time, NULL);
}
Пример #8
0
void _set_tx_mode()
{
	uint8_t config;
	_get_register(CONFIG, &config, 1);
	if ((config & _BV(PRIM_RX)) != 0)
	{
		config &= ~_BV(PRIM_RX);
		_set_register(CONFIG, &config, 1);

		// The radio takes 130 us to power up the transmitter
		// You can delete this if you're sending large packets (I'm thinking > 25 bytes, but I'm not sure) because it
		// sending the bytes over SPI can take this long.
		_delay_us(65);
		_delay_us(65);
	}
}
Пример #9
0
void Radio_Configure(RADIO_DATA_RATE dr, RADIO_TX_POWER power)
{
	uint8_t value;

	if (power < RADIO_LOWEST_POWER || power > RADIO_HIGHEST_POWER
			|| dr < RADIO_1MBPS || dr > RADIO_2MBPS)
		return;

	// set the data rate and power bits in the RF_SETUP register
	_get_register(RF_SETUP, &value, 1);

	value |= 3 << RF_PWR;	// set the power bits so that the & will mask the power value in properly.
	value &= power << RF_PWR;	// mask the power value into the RF status byte.

	if (dr)
		value |= _BV(RF_DR);
	else
		value &= ~_BV(RF_DR);

	_set_register(RF_SETUP, &value, 1);
}