sort functions
This commit is contained in:
parent
0252a2803b
commit
54cb98634e
@ -13,7 +13,7 @@ options:
|
|||||||
@echo "CC = ${CC}"
|
@echo "CC = ${CC}"
|
||||||
@echo "INSTALLDIR = ${INSTALLDIR}"
|
@echo "INSTALLDIR = ${INSTALLDIR}"
|
||||||
|
|
||||||
.c.o:
|
.cpp.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@${CC} -c ${CFLAGS} $<
|
@${CC} -c ${CFLAGS} $<
|
||||||
|
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include "cwprotocol.h"
|
|
||||||
|
|
||||||
int prepare_id (struct data_packet_format *id_packet, char *id)
|
|
||||||
{
|
|
||||||
id_packet->command = DAT;
|
|
||||||
id_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
|
||||||
snprintf(id_packet->id, SIZE_ID, id, "%s");
|
|
||||||
id_packet->sequence = 0;
|
|
||||||
id_packet->n = 0;
|
|
||||||
snprintf(id_packet->status, SIZE_ID, INTERFACE_VERSION);
|
|
||||||
id_packet->a21 = 1; /* These magic numbers was provided by Les Kerr */
|
|
||||||
id_packet->a22 = 755;
|
|
||||||
id_packet->a23 = 65535;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int prepare_tx (struct data_packet_format *tx_packet, char *id)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
tx_packet->command = DAT;
|
|
||||||
tx_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
|
||||||
snprintf(tx_packet->id, SIZE_ID, id, "%s");
|
|
||||||
tx_packet->sequence = 0;
|
|
||||||
tx_packet->n = 0;
|
|
||||||
for(i = 1; i < 51; i++)tx_packet->code[i] = 0;
|
|
||||||
tx_packet->a21 = 0; /* These magic numbers was provided by Les Kerr */
|
|
||||||
tx_packet->a22 = 755;
|
|
||||||
tx_packet->a23 = 16777215;
|
|
||||||
snprintf(tx_packet->status, SIZE_STATUS, "?");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
84
src/cwprotocol.cpp
Normal file
84
src/cwprotocol.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include "cwprotocol.h"
|
||||||
|
|
||||||
|
/* Global variables */
|
||||||
|
struct command_packet_format connect_packet = {CON, DEFAULT_CHANNEL};
|
||||||
|
struct command_packet_format disconnect_packet = {DIS, 0};
|
||||||
|
struct data_packet_format id_packet;
|
||||||
|
struct data_packet_format rx_data_packet;
|
||||||
|
struct data_packet_format tx_data_packet;
|
||||||
|
|
||||||
|
int tx_sequence = 0, rx_sequence;
|
||||||
|
int fd_socket;
|
||||||
|
|
||||||
|
int prepare_id (struct data_packet_format *id_packet, char *id)
|
||||||
|
{
|
||||||
|
id_packet->command = DAT;
|
||||||
|
id_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
||||||
|
snprintf(id_packet->id, SIZE_ID, id, "%s");
|
||||||
|
id_packet->sequence = 0;
|
||||||
|
id_packet->n = 0;
|
||||||
|
snprintf(id_packet->status, SIZE_ID, INTERFACE_VERSION);
|
||||||
|
id_packet->a21 = 1; /* These magic numbers was provided by Les Kerr */
|
||||||
|
id_packet->a22 = 755;
|
||||||
|
id_packet->a23 = 65535;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int prepare_tx (struct data_packet_format *tx_packet, char *id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tx_packet->command = DAT;
|
||||||
|
tx_packet->length = SIZE_DATA_PACKET_PAYLOAD;
|
||||||
|
snprintf(tx_packet->id, SIZE_ID, id, "%s");
|
||||||
|
tx_packet->sequence = 0;
|
||||||
|
tx_packet->n = 0;
|
||||||
|
for(i = 1; i < 51; i++)tx_packet->code[i] = 0;
|
||||||
|
tx_packet->a21 = 0; /* These magic numbers was provided by Les Kerr */
|
||||||
|
tx_packet->a22 = 755;
|
||||||
|
tx_packet->a23 = 16777215;
|
||||||
|
snprintf(tx_packet->status, SIZE_STATUS, "?");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// connect to server and send my id.
|
||||||
|
void identifyclient(void)
|
||||||
|
{
|
||||||
|
tx_sequence++;
|
||||||
|
id_packet.sequence = tx_sequence;
|
||||||
|
send(fd_socket, &connect_packet, SIZE_COMMAND_PACKET, 0);
|
||||||
|
send(fd_socket, &id_packet, SIZE_DATA_PACKET, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_latch (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
tx_sequence++;
|
||||||
|
tx_data_packet.sequence = tx_sequence;
|
||||||
|
tx_data_packet.code[0] = -1;
|
||||||
|
tx_data_packet.code[1] = 1;
|
||||||
|
tx_data_packet.n = 2;
|
||||||
|
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||||
|
tx_data_packet.n = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_unlatch (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
tx_sequence++;
|
||||||
|
tx_data_packet.sequence = tx_sequence;
|
||||||
|
tx_data_packet.code[0] = -1;
|
||||||
|
tx_data_packet.code[1] = 2;
|
||||||
|
tx_data_packet.n = 2;
|
||||||
|
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
||||||
|
tx_data_packet.n = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,23 @@ struct data_packet_format{
|
|||||||
// Define the packets used
|
// Define the packets used
|
||||||
#define DEFAULT_CHANNEL 103
|
#define DEFAULT_CHANNEL 103
|
||||||
|
|
||||||
|
/* Define functions provided by cwprotocol */
|
||||||
int prepare_id (struct data_packet_format *id_packet, char *id);
|
int prepare_id (struct data_packet_format *id_packet, char *id);
|
||||||
int prepare_tx (struct data_packet_format *tx_packet, char *id);
|
int prepare_tx (struct data_packet_format *tx_packet, char *id);
|
||||||
|
void identifyclient (void);
|
||||||
|
int send_latch (void);
|
||||||
|
int send_unlatch (void);
|
||||||
|
|
||||||
|
/* Define external struct for global variables */
|
||||||
|
extern struct command_packet_format connect_packet;
|
||||||
|
extern struct command_packet_format disconnect_packet;
|
||||||
|
extern struct data_packet_format id_packet;
|
||||||
|
extern struct data_packet_format rx_data_packet;
|
||||||
|
extern struct data_packet_format tx_data_packet;
|
||||||
|
|
||||||
|
extern int tx_sequence, rx_sequence;
|
||||||
|
|
||||||
|
extern int fd_socket;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,21 +35,13 @@
|
|||||||
#include <asm-generic/termios.h>
|
#include <asm-generic/termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//#define DEBUG 1
|
//#define DEBUG 1
|
||||||
|
|
||||||
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
#define MAXDATASIZE 1024 // max number of bytes we can get at once
|
||||||
|
|
||||||
#include "cwprotocol.h"
|
#include "cwprotocol.h"
|
||||||
|
|
||||||
struct command_packet_format connect_packet = {CON, DEFAULT_CHANNEL};
|
int serial_status = 0, fd_serial, numbytes;
|
||||||
struct command_packet_format disconnect_packet = {DIS, 0};
|
|
||||||
struct data_packet_format id_packet;
|
|
||||||
struct data_packet_format rx_data_packet;
|
|
||||||
struct data_packet_format tx_data_packet;
|
|
||||||
|
|
||||||
int serial_status = 0, fd_serial, fd_socket, numbytes;
|
|
||||||
int tx_sequence = 0, rx_sequence;
|
|
||||||
|
|
||||||
double tx_timeout = 0;
|
double tx_timeout = 0;
|
||||||
long tx_timer = 0;
|
long tx_timer = 0;
|
||||||
@ -84,7 +76,6 @@ void current_utc_time(struct timespec *ts) {
|
|||||||
#else
|
#else
|
||||||
clock_gettime(CLOCK_REALTIME, ts);
|
clock_gettime(CLOCK_REALTIME, ts);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a better clock() in milliseconds */
|
/* a better clock() in milliseconds */
|
||||||
@ -125,14 +116,6 @@ void *get_in_addr(struct sockaddr *sa)
|
|||||||
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect to server and send my id.
|
|
||||||
void identifyclient(void)
|
|
||||||
{
|
|
||||||
tx_sequence++;
|
|
||||||
id_packet.sequence = tx_sequence;
|
|
||||||
send(fd_socket, &connect_packet, SIZE_COMMAND_PACKET, 0);
|
|
||||||
send(fd_socket, &id_packet, SIZE_DATA_PACKET, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// disconnect from the server
|
// disconnect from the server
|
||||||
void inthandler(int sig)
|
void inthandler(int sig)
|
||||||
@ -176,31 +159,6 @@ void txloop (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_latch (void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
tx_sequence++;
|
|
||||||
tx_data_packet.sequence = tx_sequence;
|
|
||||||
tx_data_packet.code[0] = -1;
|
|
||||||
tx_data_packet.code[1] = 1;
|
|
||||||
tx_data_packet.n = 2;
|
|
||||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
|
||||||
tx_data_packet.n = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_unlatch (void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
tx_sequence++;
|
|
||||||
tx_data_packet.sequence = tx_sequence;
|
|
||||||
tx_data_packet.code[0] = -1;
|
|
||||||
tx_data_packet.code[1] = 2;
|
|
||||||
tx_data_packet.n = 2;
|
|
||||||
for(i = 0; i < 5; i++) send(fd_socket, &tx_data_packet, SIZE_DATA_PACKET, 0);
|
|
||||||
tx_data_packet.n = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void message(int msg)
|
void message(int msg)
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user