initialization of packets

This commit is contained in:
Gerolf Ziegenhain 2015-01-04 15:26:52 +01:00
parent 12f2d905ce
commit 765cb854ed
4 changed files with 54 additions and 40 deletions

View File

@ -1,4 +1,4 @@
SRC = irmc.c SRC = irmc.c cwprotocol.c
OBJ = ${SRC:.c=.o} OBJ = ${SRC:.c=.o}
LDFLAGS = -L/usr/local/lib -L/opt/local/lib -lm -lmorse LDFLAGS = -L/usr/local/lib -L/opt/local/lib -lm -lmorse
CFLAGS = -I/usr/local/include -I/opt/local/include -Wall CFLAGS = -I/usr/local/include -I/opt/local/include -Wall

View File

@ -1,9 +1,36 @@
id_packet.command = DAT; #include <stdio.h>
id_packet.length = 492; #include "cwprotocol.h"
snprintf(id_packet.id, 128, id, "%s");
id_packet.sequence = 0; int prepare_id (struct data_packet_format *id_packet, char *id)
id_packet.n = 0; {
snprintf(id_packet.status, 128, "irmc v0.02"); id_packet->command = DAT;
id_packet.a21 = 1; /* These magic numbers was provided by Les Kerr */ id_packet->length = SIZE_DATA_PACKET_PAYLOAD;
id_packet.a22 = 755; snprintf(id_packet->id, SIZE_ID, id, "%s");
id_packet.a23 = 65535; id_packet->sequence = 0;
id_packet->n = 0;
snprintf(id_packet->status, SIZE_ID, "irmc v0.02");
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;
}

View File

@ -11,10 +11,12 @@ struct command_packet_format{
}; };
#define SIZE_COMMAND_PACKET 4 #define SIZE_COMMAND_PACKET 4
// This structure will be used for id, rx and tx packets // This structure will be used for id, rx and tx packets
#define SIZE_ID 128
#define SIZE_STATUS 128
struct data_packet_format{ struct data_packet_format{
unsigned short command; unsigned short command;
unsigned short length; unsigned short length;
char id[128]; char id[SIZE_ID];
char a1[4]; char a1[4];
unsigned int sequence; unsigned int sequence;
unsigned int a21; unsigned int a21;
@ -22,18 +24,16 @@ struct data_packet_format{
unsigned int a23; unsigned int a23;
signed int code[51]; signed int code[51];
unsigned int n; unsigned int n;
char status[128]; /* This is called version in MorseKob */ char status[SIZE_STATUS]; /* This is called version in MorseKob */
char a4[8]; char a4[8];
}; };
#define SIZE_DATA_PACKET 496 #define SIZE_DATA_PACKET 496
#define SIZE_DATA_PACKET_PAYLOAD 492 // = SIZE_DATA_PACKET - SIZE_COMMAND_PACKET
// Define the packets used // Define the packets used
#define DEFAULT_CHANNEL 103 #define DEFAULT_CHANNEL 103
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 prepare_id (struct data_packet_format *id_packet, char *id);
int prepare_tx (struct data_packet_format *tx_packet, char *id);

View File

@ -36,7 +36,11 @@
#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};
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 serial_status = 0, fd_serial, fd_socket, numbytes;
int tx_sequence = 0, rx_sequence; int tx_sequence = 0, rx_sequence;
@ -263,7 +267,7 @@ int main(int argc, char *argv[])
char hostname[64]; char hostname[64];
char port[16]; char port[16];
int channel; int channel;
char id[128]; char id[SIZE_ID];
char serialport[64]; char serialport[64];
if (argc < 4) { if (argc < 4) {
@ -274,30 +278,13 @@ int main(int argc, char *argv[])
snprintf(hostname, 64, argv[1], "%s"); snprintf(hostname, 64, argv[1], "%s");
snprintf(port, 16, argv[2], "%s"); snprintf(port, 16, argv[2], "%s");
channel = atoi(argv[3]); channel = atoi(argv[3]);
if(argc > 4) snprintf(id, 128, argv[4], "%s"); if(argc > 4) snprintf(id, SIZE_ID, argv[4], "%s");
else snprintf(id, 128, "irmc"); else snprintf(id, SIZE_ID, "irmc");
if(argc > 5) snprintf(serialport, 64, argv[5], "%s"); if(argc > 5) snprintf(serialport, 64, argv[5], "%s");
id_packet.command = DAT; prepare_id (&id_packet, id);
id_packet.length = 492; prepare_tx (&tx_data_packet, id);
snprintf(id_packet.id, 128, id, "%s");
id_packet.sequence = 0;
id_packet.n = 0;
snprintf(id_packet.status, 128, "irmc v0.02");
id_packet.a21 = 1; /* These magic numbers was provided by Les Kerr */
id_packet.a22 = 755;
id_packet.a23 = 65535;
tx_data_packet.command = DAT;
tx_data_packet.length = 492;
snprintf(tx_data_packet.id, 128, id, "%s");
tx_data_packet.sequence = 0;
tx_data_packet.n = 0;
for(i = 1; i < 51; i++)tx_data_packet.code[i] = 0;
tx_data_packet.a21 = 0; /* These magic numbers was provided by Les Kerr */
tx_data_packet.a22 = 755;
tx_data_packet.a23 = 16777215;
snprintf(tx_data_packet.status, 128, "?");
connect_packet.command = CON; connect_packet.command = CON;
connect_packet.channel = channel; connect_packet.channel = channel;