#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/timeb.h>
#ifdef __linux__
#include <unistd.h>
#else
#include <windows.h>
#endif
{
}
void DeviceData(const char *record_library_device_name,
int packet_length,
unsigned char *packet_buffer_ptr)
{
{
printf("Successfully closed record file with pathname: %s.\n",
}
}
void ByteSwap4Bytes(unsigned char *packet)
{
unsigned char buffer[4];
memmove(buffer, packet, 4);
memmove(packet, &buffer[3], 1);
memmove(packet + 1, &buffer[2], 1);
memmove(packet + 2, &buffer[1], 1);
memmove(packet + 3, &buffer[0], 1);
}
void CreateDataPackets(unsigned char *packet1_ptr,
unsigned char *packet2_ptr,
unsigned char *packet3_ptr,
unsigned char *packet4_ptr,
unsigned short *length1_ptr,
unsigned short *length2_ptr,
unsigned short *length3_ptr,
unsigned short *length4_ptr)
{
unsigned short tester= 1;
unsigned char tester_byte[1];
unsigned short big_endian_order = 1;
struct timeb current_time;
unsigned int tim;
memcpy(tester_byte,&tester,1);
if (tester_byte[0] == 0x01)
{
big_endian_order = 0;
}
memset(packet1_ptr,0x00,50);
memset(packet2_ptr,0x00,50);
memset(packet3_ptr,0x00,50);
memset(packet4_ptr,0x00,50);
if (big_endian_order == 1)
{
ftime(¤t_time);
tim = (unsigned int)current_time.time;
memmove(packet1_ptr+2, (unsigned char*)&tim,4);
memmove(packet1_ptr+6, (unsigned char*)¤t_time.millitm,2);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
memmove(packet2_ptr+2, (unsigned char*)&tim,4);
memmove(packet2_ptr+6, (unsigned char*)¤t_time.millitm,2);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
memmove(packet3_ptr+2, (unsigned char*)&tim,4);
memmove(packet3_ptr+6, (unsigned char*)¤t_time.millitm,2);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
memmove(packet4_ptr+2,(unsigned char*)&tim,4);
memmove(packet4_ptr+6,(unsigned char*)¤t_time.millitm,2);
}
else
{
ftime(¤t_time);
tim = (unsigned int)current_time.time;
ByteSwap4Bytes((unsigned char*)&tim);
memmove(packet1_ptr + 2, (unsigned char*)&tim, 4);
memmove(packet1_ptr+6, (unsigned char*)¤t_time.millitm+1,1);
memmove(packet1_ptr+7, (unsigned char*)¤t_time.millitm,1);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
ByteSwap4Bytes((unsigned char*)&tim);
memmove(packet2_ptr + 2, (unsigned char*)&tim, 4);
memmove(packet2_ptr+6, (unsigned char*)¤t_time.millitm+1,1);
memmove(packet2_ptr+7, (unsigned char*)¤t_time.millitm,1);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
ByteSwap4Bytes((unsigned char*)&tim);
memmove(packet3_ptr + 2, (unsigned char*)&tim, 4);
memmove(packet3_ptr+6, (unsigned char*)¤t_time.millitm+1,1);
memmove(packet3_ptr+7, (unsigned char*)¤t_time.millitm,1);
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
ftime(¤t_time);
tim = (unsigned int)current_time.time;
ByteSwap4Bytes((unsigned char*)&tim);
memmove(packet4_ptr + 2, (unsigned char*)&tim, 4);
memmove(packet4_ptr+6, (unsigned char*)¤t_time.millitm+1,1);
memmove(packet4_ptr+7, (unsigned char*)¤t_time.millitm,1);
}
strcpy((char *)packet1_ptr+8,"Mary had a little lamb");
strcpy((char *)packet2_ptr+8,"Its feet were black as soot");
strcpy((char *)packet3_ptr+8,"And into Mary's bread and jam ");
strcpy((char *)packet4_ptr+8,"Its sooty foot it put");
*length1_ptr = (unsigned short)strlen(packet1_ptr+8) + 8;
*length2_ptr = (unsigned short)strlen(packet2_ptr+8) + 8;
*length3_ptr = (unsigned short)strlen(packet3_ptr+8) + 8;
*length4_ptr = (unsigned short)strlen(packet4_ptr+8) + 8;
if (big_endian_order == 1)
{
memmove(packet1_ptr,length1_ptr,2);
memmove(packet2_ptr,length2_ptr,2);
memmove(packet3_ptr,length3_ptr,2);
memmove(packet4_ptr,length4_ptr,2);
}
else
{
memmove(packet1_ptr+1,length1_ptr,1);
memmove(packet2_ptr+1,length2_ptr,1);
memmove(packet3_ptr+1,length3_ptr,1);
memmove(packet4_ptr+1,length4_ptr,1);
}
return;
}
int main(int argc, char *argv[])
{
unsigned char packet1[50];
unsigned char packet2[50];
unsigned char packet3[50];
unsigned char packet4[50];
unsigned short length1;
unsigned short length2;
unsigned short length3;
unsigned short length4;
char pathname[256];
char record_filename[256];
char time_tagged_record_file_name[256];
unsigned int time_tagged_record_file_name_buffer_size;
int return_value;
strcpy (pathname, "./record_api_config.txt");
if (argc == 2)
{
strcpy(pathname,argv[1]);
}
else if (argc > 2)
{
printf("Error Command line contains too many arguments.\n");
return 0;
}
printf("\nRecord TCP\n\n");
printf("Create four data packets.\n");
CreateDataPackets(packet1,
packet2,
packet3,
packet4,
&length1,
&length2,
&length3,
&length4);
{
{
return 0;
}
strcpy(record_filename,"pkt1andpkt2");
{
return 0;
}
{
return 0;
}
time_tagged_record_file_name_buffer_size = sizeof(time_tagged_record_file_name);
&time_tagged_record_file_name_buffer_size, time_tagged_record_file_name)) ==
SUCCESS)
{
printf("First time tagged record file name: %s\n", time_tagged_record_file_name);
}
else
{
return 0;
}
strcpy(record_filename,"pkt3andpkt4");
{
return 0;
}
{
return 0;
}
&time_tagged_record_file_name_buffer_size, time_tagged_record_file_name)) ==
SUCCESS)
{
printf("Second time tagged record file name: %s\n", time_tagged_record_file_name);
}
else
{
return 0;
}
}
#ifdef __linux__
sleep(1);
#else
Sleep(1000);
#endif
return 0;
}
Message codes and structure definition for the Device Service library.
#define DS_CLOSE
4 DS message code for Close
Definition: ds_shared.h:29
Structure of parameters needed for message support.
Definition: trek_toolkit_common_api_ansi_c.h:74
char message[MAX_MESSAGE_SIZE]
Message.
Definition: trek_toolkit_common_api_ansi_c.h:77
enum message_category category
Message category (e.g., MSG_CAT_ERROR, MSG_CAT_ERROR_ALERT, MSG_CAT_WARNING, MSG_CAT_WARNING_ALERT,...
Definition: trek_toolkit_common_api_ansi_c.h:76
Structure of parameters needed for record device status.
Definition: ds_shared.h:198
char record_path_and_filename[256]
Path and filename of closed record file.
Definition: ds_shared.h:202
unsigned long ds_message_code
DS message code describing the event (i.e., DS_CLOSE, a record file was closed).
Definition: ds_shared.h:199
#define SUCCESS
The function completed successfully.
Definition: trek_error.h:8