Indented with indent.sh script.
This commit is contained in:
@@ -49,11 +49,13 @@ typedef HANDLE sem_t;
|
||||
|
||||
struct timespec {
|
||||
time_t tv_sec; /* Seconds */
|
||||
long tv_nsec; /* Nanoseconds [0 .. 999999999] */
|
||||
long tv_nsec; /* Nanoseconds [0 .. 999999999] */
|
||||
};
|
||||
|
||||
|
||||
static inline int gettimeofday(struct timeval *tp, void *tzp)
|
||||
static inline int gettimeofday(
|
||||
struct timeval *tp,
|
||||
void *tzp)
|
||||
{
|
||||
struct _timeb timebuffer;
|
||||
|
||||
@@ -65,20 +67,21 @@ static inline int gettimeofday(struct timeval *tp, void *tzp)
|
||||
}
|
||||
|
||||
/* FIXME: not a complete implementation of the posix function */
|
||||
static inline int sem_timedwait(sem_t *sem,
|
||||
static inline int sem_timedwait(
|
||||
sem_t * sem,
|
||||
const struct timespec *abs_timeout)
|
||||
{
|
||||
struct timeval tp;
|
||||
DWORD wait_status = 0;
|
||||
DWORD dwMilliseconds = (abs_timeout->tv_sec * 1000) +
|
||||
(abs_timeout->tv_nsec / 1000);
|
||||
DWORD dwMilliseconds =
|
||||
(abs_timeout->tv_sec * 1000) + (abs_timeout->tv_nsec / 1000);
|
||||
|
||||
gettimeofday(&tp,NULL);
|
||||
gettimeofday(&tp, NULL);
|
||||
if (abs_timeout->tv_sec >= tp.tv_sec) {
|
||||
dwMilliseconds = (abs_timeout->tv_sec - tp.tv_sec) * 1000;
|
||||
if (abs_timeout->tv_nsec >= (tp.tv_usec*1000)) {
|
||||
if (abs_timeout->tv_nsec >= (tp.tv_usec * 1000)) {
|
||||
dwMilliseconds +=
|
||||
((abs_timeout->tv_nsec - (tp.tv_usec*1000)) / (1000*1000));
|
||||
((abs_timeout->tv_nsec - (tp.tv_usec * 1000)) / (1000 * 1000));
|
||||
}
|
||||
} else {
|
||||
dwMilliseconds = 0;
|
||||
@@ -91,14 +94,16 @@ static inline int sem_timedwait(sem_t *sem,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
static inline int sem_init(
|
||||
sem_t * sem,
|
||||
int pshared,
|
||||
unsigned int value)
|
||||
{
|
||||
(void)pshared;
|
||||
*sem = CreateSemaphore(
|
||||
NULL/*lpSecurityDescriptor*/,
|
||||
value /* lInitialCount */,
|
||||
1 /* lMaximumCount */,
|
||||
NULL /* lpName */);
|
||||
(void) pshared;
|
||||
*sem = CreateSemaphore(NULL /*lpSecurityDescriptor */ ,
|
||||
value /* lInitialCount */ ,
|
||||
1 /* lMaximumCount */ ,
|
||||
NULL /* lpName */ );
|
||||
if ((*sem) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -106,13 +111,14 @@ static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
static inline int nanosleep(
|
||||
const struct timespec *rqtp,
|
||||
struct timespec *rmtp)
|
||||
{
|
||||
DWORD dwMilliseconds = (rqtp->tv_sec * 1000) +
|
||||
(rqtp->tv_nsec / 1000);
|
||||
DWORD dwMilliseconds = (rqtp->tv_sec * 1000) + (rqtp->tv_nsec / 1000);
|
||||
|
||||
Sleep(dwMilliseconds);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ void RS485_Set_Interface(
|
||||
}
|
||||
}
|
||||
|
||||
const char *RS485_Interface(void)
|
||||
const char *RS485_Interface(
|
||||
void)
|
||||
{
|
||||
return RS485_Port_Name;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ extern "C" {
|
||||
|
||||
void RS485_Set_Interface(
|
||||
char *ifname);
|
||||
const char * RS485_Interface(void);
|
||||
const char *RS485_Interface(
|
||||
void);
|
||||
|
||||
void RS485_Initialize(
|
||||
void);
|
||||
|
||||
@@ -55,20 +55,20 @@
|
||||
/* file format for libpcap/winpcap */
|
||||
/* from http://wiki.wireshark.org/Development/LibpcapFileFormat */
|
||||
typedef struct pcap_hdr_s {
|
||||
uint32_t magic_number; /* magic number */
|
||||
uint16_t version_major; /* major version number */
|
||||
uint16_t version_minor; /* minor version number */
|
||||
int32_t thiszone; /* GMT to local correction */
|
||||
uint32_t sigfigs; /* accuracy of timestamps */
|
||||
uint32_t snaplen; /* max length of captured packets, in octets */
|
||||
uint32_t network; /* data link type */
|
||||
uint32_t magic_number; /* magic number */
|
||||
uint16_t version_major; /* major version number */
|
||||
uint16_t version_minor; /* minor version number */
|
||||
int32_t thiszone; /* GMT to local correction */
|
||||
uint32_t sigfigs; /* accuracy of timestamps */
|
||||
uint32_t snaplen; /* max length of captured packets, in octets */
|
||||
uint32_t network; /* data link type */
|
||||
} pcap_hdr_t;
|
||||
|
||||
typedef struct pcaprec_hdr_s {
|
||||
uint32_t ts_sec; /* timestamp seconds */
|
||||
uint32_t ts_usec; /* timestamp microseconds */
|
||||
uint32_t incl_len; /* number of octets of packet saved in file */
|
||||
uint32_t orig_len; /* actual length of packet */
|
||||
uint32_t ts_sec; /* timestamp seconds */
|
||||
uint32_t ts_usec; /* timestamp microseconds */
|
||||
uint32_t incl_len; /* number of octets of packet saved in file */
|
||||
uint32_t orig_len; /* actual length of packet */
|
||||
} pcaprec_hdr_t;
|
||||
|
||||
/* local port data - shared with RS-485 */
|
||||
@@ -169,9 +169,9 @@ static void print_received_packet(
|
||||
|
||||
/* returns a delta timestamp */
|
||||
void timestamp(
|
||||
uint32_t *ts_sec, /* timestamp seconds since epoch (Unix) */
|
||||
uint32_t *ts_usec) /* timestamp microseconds (unix) */
|
||||
{
|
||||
uint32_t * ts_sec, /* timestamp seconds since epoch (Unix) */
|
||||
uint32_t * ts_usec)
|
||||
{ /* timestamp microseconds (unix) */
|
||||
DWORD ticks = 0;
|
||||
static DWORD initial_ticks = 0;
|
||||
static time_t initial_seconds = 0;
|
||||
@@ -185,7 +185,7 @@ void timestamp(
|
||||
}
|
||||
ticks = GetTickCount();
|
||||
/* how much total time has passed? */
|
||||
elapsed_ticks = ticks - initial_ticks;
|
||||
elapsed_ticks = ticks - initial_ticks;
|
||||
seconds = elapsed_ticks / 1000;
|
||||
milliseconds = elapsed_ticks - (seconds * 1000);
|
||||
*ts_sec = initial_seconds + seconds;
|
||||
@@ -195,55 +195,56 @@ void timestamp(
|
||||
}
|
||||
|
||||
static const char *Capture_Filename = "mstp.cap";
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
|
||||
/* write packet to file in libpcap format */
|
||||
static void write_global_header(void)
|
||||
static void write_global_header(
|
||||
void)
|
||||
{
|
||||
uint32_t magic_number = 0xa1b2c3d4; /* magic number */
|
||||
uint16_t version_major = 2; /* major version number */
|
||||
uint16_t version_minor = 4; /* minor version number */
|
||||
int32_t thiszone = 0; /* GMT to local correction */
|
||||
uint32_t sigfigs = 0; /* accuracy of timestamps */
|
||||
uint32_t snaplen = 65535; /* max length of captured packets, in octets */
|
||||
uint32_t network = 165; /* data link type */
|
||||
int32_t thiszone = 0; /* GMT to local correction */
|
||||
uint32_t sigfigs = 0; /* accuracy of timestamps */
|
||||
uint32_t snaplen = 65535; /* max length of captured packets, in octets */
|
||||
uint32_t network = 165; /* data link type */
|
||||
|
||||
/* create a new file. */
|
||||
pFile = fopen(Capture_Filename, "wb");
|
||||
if (pFile) {
|
||||
fwrite(&magic_number,sizeof(magic_number),1,pFile);
|
||||
fwrite(&version_major,sizeof(version_major),1,pFile);
|
||||
fwrite(&version_minor,sizeof(version_minor),1,pFile);
|
||||
fwrite(&thiszone,sizeof(thiszone),1,pFile);
|
||||
fwrite(&sigfigs,sizeof(sigfigs),1,pFile);
|
||||
fwrite(&snaplen,sizeof(snaplen),1,pFile);
|
||||
fwrite(&network,sizeof(network),1,pFile);
|
||||
fwrite(&magic_number, sizeof(magic_number), 1, pFile);
|
||||
fwrite(&version_major, sizeof(version_major), 1, pFile);
|
||||
fwrite(&version_minor, sizeof(version_minor), 1, pFile);
|
||||
fwrite(&thiszone, sizeof(thiszone), 1, pFile);
|
||||
fwrite(&sigfigs, sizeof(sigfigs), 1, pFile);
|
||||
fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
fwrite(&network, sizeof(network), 1, pFile);
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void write_received_packet(
|
||||
volatile struct mstp_port_struct_t *mstp_port)
|
||||
{
|
||||
uint32_t ts_sec; /* timestamp seconds */
|
||||
uint32_t ts_usec; /* timestamp microseconds */
|
||||
uint32_t incl_len; /* number of octets of packet saved in file */
|
||||
uint32_t orig_len; /* actual length of packet */
|
||||
uint8_t header[8]; /* MS/TP header */
|
||||
uint32_t ts_sec; /* timestamp seconds */
|
||||
uint32_t ts_usec; /* timestamp microseconds */
|
||||
uint32_t incl_len; /* number of octets of packet saved in file */
|
||||
uint32_t orig_len; /* actual length of packet */
|
||||
uint8_t header[8]; /* MS/TP header */
|
||||
|
||||
if (pFile) {
|
||||
timestamp(&ts_sec, &ts_usec);
|
||||
fwrite(&ts_sec,sizeof(ts_sec),1,pFile);
|
||||
fwrite(&ts_usec,sizeof(ts_usec),1,pFile);
|
||||
fwrite(&ts_sec, sizeof(ts_sec), 1, pFile);
|
||||
fwrite(&ts_usec, sizeof(ts_usec), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
incl_len = orig_len = 8 + mstp_port->DataLength + 2;
|
||||
} else {
|
||||
incl_len = orig_len = 8;
|
||||
}
|
||||
fwrite(&incl_len,sizeof(incl_len),1,pFile);
|
||||
fwrite(&orig_len,sizeof(orig_len),1,pFile);
|
||||
fwrite(&incl_len, sizeof(incl_len), 1, pFile);
|
||||
fwrite(&orig_len, sizeof(orig_len), 1, pFile);
|
||||
header[0] = 0x55;
|
||||
header[1] = 0xFF;
|
||||
header[2] = mstp_port->FrameType;
|
||||
@@ -252,25 +253,26 @@ static void write_received_packet(
|
||||
header[5] = HI_BYTE(mstp_port->DataLength);
|
||||
header[6] = LO_BYTE(mstp_port->DataLength);
|
||||
header[7] = mstp_port->HeaderCRCActual;
|
||||
fwrite(header,sizeof(header),1,pFile);
|
||||
fwrite(header, sizeof(header), 1, pFile);
|
||||
if (mstp_port->DataLength) {
|
||||
fwrite(mstp_port->InputBuffer,mstp_port->DataLength,1,pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualMSB),1,1,pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualLSB),1,1,pFile);
|
||||
fwrite(mstp_port->InputBuffer, mstp_port->DataLength, 1, pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualMSB), 1, 1, pFile);
|
||||
fwrite(&(mstp_port->DataCRCActualLSB), 1, 1, pFile);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static char *Network_Interface = NULL;
|
||||
|
||||
static void cleanup(void)
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
if (pFile) {
|
||||
fflush(pFile); /* stream pointer */
|
||||
fclose(pFile); /* stream pointer */
|
||||
fflush(pFile); /* stream pointer */
|
||||
fclose(pFile); /* stream pointer */
|
||||
}
|
||||
pFile = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user