1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/*=========================================================================
Program: OpenIGTLink Library
Module: $RCSfile: $
Language: C
Date: $Date: $
Version: $Revision: $
Copyright (c) Insight Software Consortium. All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <string.h>
#include "igtl_util.h"
#include "igtl_header.h"
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
char barray[] = {
0x00, 0x01, /* Version number */
0x54, 0x59, 0x50, 0x45, 0x4e, 0x41, 0x4d, 0x45,
0x00, 0x00, 0x00, 0x00, /* TYPENAME */
0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4e, 0x61,
0x6d, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, /* Device name */
0x00, 0x00, 0x00, 0x00, 0x49, 0x96, 0x02, 0xd2, /* Time stamp */
0x00, 0x00, 0x00, 0x07, 0x50, 0x88, 0xFF, 0x06, /* Body size */
0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x7E, 0xA7, /* CRC */
};
int main( int argc, char * argv [] )
{
igtl_header header;
// Test structure size
if (sizeof(header) != IGTL_HEADER_SIZE)
{
fprintf(stdout, "Invalid size of header structure.\n");
return EXIT_FAILURE;
}
// Test binary
header.header_version = 1;
strncpy( header.name, "TYPENAME", 12 );
strncpy( header.device_name, "DeviceName", 20 );
header.timestamp = 1234567890;
header.body_size = 31415926534;
header.crc = 1343143;
igtl_header_convert_byte_order( &header );
if (memcmp((const void*)&header, (const void*)barray, IGTL_HEADER_SIZE) == 0)
{
return EXIT_SUCCESS;
}
else
{
/* Print message as HEX values in STDERR for debug */
fprintf(stdout, "\n===== First %d bytes of the test message =====\n", IGTL_HEADER_SIZE);
igtl_message_dump_hex(stdout, (const void*)&header, IGTL_HEADER_SIZE);
return EXIT_FAILURE;
}
}
|