Added FCP monitoring test.

git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@15 53a565d1-3bb7-0310-b661-cf11e63c67ab
This commit is contained in:
aeb 2000-03-16 22:22:05 +00:00
parent 106b50af9d
commit bd7a5606d2
2 changed files with 46 additions and 7 deletions

View File

@ -6,7 +6,7 @@
#include "kernel-raw1394.h"
#include "raw1394_private.h"
static int do_fcp_listen(struct raw1394_handle *handle)
static int do_fcp_listen(struct raw1394_handle *handle, int startstop)
{
struct sync_cb_data sd = { 0, 0 };
struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, &sd };
@ -16,7 +16,7 @@ static int do_fcp_listen(struct raw1394_handle *handle)
CLEAR_REQ(req);
req->type = RAW1394_REQ_FCP_LISTEN;
req->generation = handle->generation;
req->misc = 0;
req->misc = startstop;
req->tag = (unsigned long)&rh;
req->recvb = handle->buffer;
req->length = 512;
@ -44,10 +44,10 @@ static int do_fcp_listen(struct raw1394_handle *handle)
int raw1394_start_fcp_listen(struct raw1394_handle *handle)
{
return do_fcp_listen(handle);
return do_fcp_listen(handle, 1);
}
int raw1394_stop_fcp_listen(struct raw1394_handle *handle)
{
return do_fcp_listen(handle);
return do_fcp_listen(handle, 0);
}

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <errno.h>
#include <sys/poll.h>
#include "raw1394.h"
#include "csr.h"
@ -17,13 +18,12 @@ const char not_loaded[] = "\
This probably means that you don't have raw1394 support in the kernel or that
you haven't loaded the raw1394 module.\n";
quadlet_t buffer;
int my_tag_handler(raw1394handle_t handle, unsigned long tag, int error)
{
if (error < 0) {
printf("completed with error %d\n", error);
printf("failed with error %d\n", error);
} else {
printf("completed with 0x%08x, value 0x%08x\n", error, buffer);
}
@ -31,6 +31,20 @@ int my_tag_handler(raw1394handle_t handle, unsigned long tag, int error)
return 0;
}
int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
size_t length, unsigned char *data)
{
printf("got fcp %s from node %d of %d bytes:",
(response ? "response" : "command"), nodeid & 0x3f, length);
while (length) {
printf(" %02x", *data);
data++;
length--;
}
printf("\n");
}
int main(int argc, char **argv)
@ -41,7 +55,9 @@ int main(int argc, char **argv)
tag_handler_t std_handler;
int retval;
struct pollfd pfd;
unsigned char fcp_test[] = { 0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
handle = raw1394_get_handle();
@ -115,5 +131,28 @@ int main(int argc, char **argv)
}
}
printf("\ntesting FCP monitoring on local node\n");
raw1394_set_fcp_handler(handle, my_fcp_handler);
raw1394_start_fcp_listen(handle);
retval = raw1394_write(handle, raw1394_get_local_id(handle),
CSR_REGISTER_BASE + CSR_FCP_COMMAND, sizeof(fcp_test),
(quadlet_t *)fcp_test);
retval = raw1394_write(handle, raw1394_get_local_id(handle),
CSR_REGISTER_BASE + CSR_FCP_RESPONSE, sizeof(fcp_test),
(quadlet_t *)fcp_test);
printf("\npolling for leftover messages\n");
pfd.fd = raw1394_get_fd(handle);
pfd.events = POLLIN;
pfd.revents = 0;
while (1) {
if (poll(&pfd, 1, 10) < 1) break;
raw1394_loop_iterate(handle);
}
if (retval < 0) {
perror("poll failed");
}
exit(0);
}