[aravis] fake: implement read memory in fake gv camera.



commit 9ff50fae151f02e357334bd7085e5a471c326deb
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sun May 30 16:29:24 2010 +0200

    fake: implement read memory in fake gv camera.

 src/arvfakecamera.c   |    7 +++++--
 src/arvfakegvcamera.c |   20 ++++++++++++++++++--
 src/arvgvcp.c         |   22 ++++++++++++++++++++++
 src/arvgvcp.h         |    2 ++
 4 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
index 550dc93..8f7abe8 100644
--- a/src/arvfakecamera.c
+++ b/src/arvfakecamera.c
@@ -56,6 +56,8 @@ static const char *arv_fake_camera_genicam_filename = NULL;
 gboolean
 arv_fake_camera_read_memory (ArvFakeCamera *camera, guint32 address, guint32 size, void *buffer)
 {
+	guint32 read_size;
+
 	g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), FALSE);
 	g_return_val_if_fail (buffer != NULL, FALSE);
 	g_return_val_if_fail (size > 0, FALSE);
@@ -70,9 +72,10 @@ arv_fake_camera_read_memory (ArvFakeCamera *camera, guint32 address, guint32 siz
 		return TRUE;
 	}
 
-	g_return_val_if_fail (address - ARV_FAKE_CAMERA_MEMORY_SIZE + size > camera->priv->genicam_data_size, FALSE);
+	address -= ARV_FAKE_CAMERA_MEMORY_SIZE;
+	read_size = MIN (address + size, camera->priv->genicam_data_size) - address;
 
-	memcpy (buffer, camera->priv->genicam_data + address - ARV_FAKE_CAMERA_MEMORY_SIZE, size);
+	memcpy (buffer, camera->priv->genicam_data + address, read_size);
 
 	return TRUE;
 }
diff --git a/src/arvfakegvcamera.c b/src/arvfakegvcamera.c
index b8b7678..eb5f433 100644
--- a/src/arvfakegvcamera.c
+++ b/src/arvfakegvcamera.c
@@ -1,5 +1,6 @@
 #include <arv.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define ARV_FAKE_GV_CAMERA_BUFFER_SIZE	65536
 
@@ -28,10 +29,13 @@ handle_control_packet (ArvFakeGvCamera *gv_camera, GSocket *socket,
 {
 	ArvGvcpPacket *ack_packet;
 	size_t ack_packet_size;
+	guint32 block_address;
+	guint32 block_size;
+
+	arv_gvcp_packet_debug (packet);
 
 	switch (g_ntohs (packet->header.command)) {
 		case ARV_GVCP_COMMAND_DISCOVERY_CMD:
-			arv_gvcp_packet_debug (packet);
 			ack_packet = arv_gvcp_packet_new_discovery_ack (&ack_packet_size);
 			arv_fake_camera_read_memory (gv_camera->camera, 0, ARV_GVBS_DISCOVERY_DATA_SIZE,
 						     &ack_packet->data);
@@ -40,7 +44,19 @@ handle_control_packet (ArvFakeGvCamera *gv_camera, GSocket *socket,
 			g_free (ack_packet);
 			break;
 		case ARV_GVCP_COMMAND_READ_MEMORY_CMD:
-			g_message ("Read command ");
+			memcpy (&block_address, &packet->data[0], sizeof (guint32));
+			memcpy (&block_size, &packet->data[sizeof(guint32)], sizeof (guint32));
+			block_address = g_ntohl (block_address);
+			block_size = g_ntohl (block_size);
+			ack_packet = arv_gvcp_packet_new_read_memory_ack (block_address, block_size,
+									  arv_gvcp_packet_get_packet_count (packet),
+									  &ack_packet_size);
+			arv_fake_camera_read_memory (gv_camera->camera, block_address, block_size,
+						     arv_gvcp_packet_get_read_memory_ack_data (ack_packet));
+			g_socket_send_to (socket, remote_address, (char *) ack_packet, ack_packet_size, NULL, NULL);
+			arv_gvcp_packet_debug (ack_packet);
+			g_free (ack_packet);
+			g_message ("Read command %d (%d)", block_address, block_size);
 			break;
 		default:
 			g_message ("Unknown command");
diff --git a/src/arvgvcp.c b/src/arvgvcp.c
index 60e6b3e..6a38d47 100644
--- a/src/arvgvcp.c
+++ b/src/arvgvcp.c
@@ -61,6 +61,28 @@ arv_gvcp_packet_new_read_memory_cmd (guint32 address, guint32 size, guint32 pack
 }
 
 ArvGvcpPacket *
+arv_gvcp_packet_new_read_memory_ack (guint32 address, guint32 size, guint32 packet_count, size_t *packet_size)
+{
+	ArvGvcpPacket *packet;
+	guint32 n_address = g_htonl (address);
+
+	g_return_val_if_fail (packet_size != NULL, NULL);
+
+	*packet_size = sizeof (ArvGvcpHeader) + sizeof (guint32) + size;
+
+	packet = g_malloc (*packet_size);
+
+	packet->header.packet_type = g_htons (ARV_GVCP_PACKET_TYPE_ACK);
+	packet->header.command = g_htons (ARV_GVCP_COMMAND_READ_MEMORY_ACK);
+	packet->header.size = g_htons (sizeof (guint32) + size);
+	packet->header.count = g_htons (packet_count);
+
+	memcpy (&packet->data, &n_address, sizeof (guint32));
+
+	return packet;
+}
+
+ArvGvcpPacket *
 arv_gvcp_packet_new_write_memory_cmd (guint32 address, guint32 size, guint32 packet_count, size_t *packet_size)
 {
 	ArvGvcpPacket *packet;
diff --git a/src/arvgvcp.h b/src/arvgvcp.h
index 0b33c90..11fc840 100644
--- a/src/arvgvcp.h
+++ b/src/arvgvcp.h
@@ -97,6 +97,8 @@ typedef struct {
 void 			arv_gvcp_packet_free 			(ArvGvcpPacket *packet);
 ArvGvcpPacket * 	arv_gvcp_packet_new_read_memory_cmd 	(guint32 address, guint32 size,
 								 guint32 packet_count, size_t *packet_size);
+ArvGvcpPacket * 	arv_gvcp_packet_new_read_memory_ack 	(guint32 address, guint32 size, guint32 packet_count,
+								 size_t *packet_size);
 ArvGvcpPacket * 	arv_gvcp_packet_new_write_memory_cmd	(guint32 address, guint32 size,
 								 guint32 packet_count, size_t *packet_size);
 ArvGvcpPacket * 	arv_gvcp_packet_new_read_register_cmd 	(guint32 address,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]