RCOM PROJ
File transfer via serial port
dcp.h
Go to the documentation of this file.
1 #ifndef PLA_HEADER
2 #define PLA_HEADER
3 #define _GNU_SOURCE
4 
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11 #include <termios.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <strings.h>
15 #include <unistd.h>
16 #include <signal.h>
17 #include <errno.h>
18 
19 #include "macros.h"
20 #include "logs.h"
21 #include "statemachine.h"
22 #include "dcp_spec.h"
23 
27 struct linkLayer {
28  char port[20]; /* Device /dev/ttySx, x = 0, 1*/
29  int baudRate; /*Transmission Speed*/
30  unsigned char sequenceNumber; /*Frame Sequence Number: 0x00, 0x01*/
31  unsigned int timeout; /*Alarm Timeout: x s*/
32  unsigned int numTransmissions; /*Number of tries in case of failure*/
33  unsigned char frame[MAX_SIZE_AFT_STUFF]; /*Frame with double the size of MAX_SIZE to accomodate for byte_stuffing increase*/
34  unsigned int status; /*TRANSMITTER | RECEIVER*/
35 };
36 
37 
39 struct termios oldtio;
40 volatile int failed;
41 
42 
50 int llopen(int porta, int type);
51 
60 int llwrite(int fd, char *buffer, int lenght);
61 
69 int llread(int fd, unsigned char *buffer);
70 
77 int llclose(int fd);
78 
79 #endif // PLA_HEADER
80 
stateMachineSetUp
void stateMachineSetUp(unsigned char control, unsigned char address, enum stateMachineState state, enum stateMachineType type)
Function to easily change the State Machine.
Definition: statemachine.c:9
Start
@ Start
Definition: statemachine.h:12
RECEIVER
#define RECEIVER
Definition: macros.h:45
oldtio
struct termios oldtio
used in llclose to reset termios
Definition: dcp.h:39
A_ER
#define A_ER
(0x03) Campo de Endereço (A) de commandos do Emissor, resposta do Receptor
Definition: macros.h:27
C_RR
#define C_RR(r)
(0x05 OU 0x85) Campo de Controlo - RR (receiver ready / positive ACK))
Definition: macros.h:33
Write
@ Write
Definition: statemachine.h:11
receiver_UA
int receiver_UA(int fd)
Função que recebe trama SET e envia trama UA.
Definition: dcp_spec.c:237
transmitter_SET
int transmitter_SET(int fd)
Função que envia Trama SET e recebe trama UA.
Definition: dcp_spec.c:223
transmitter_DISC_UA
int transmitter_DISC_UA(int fd)
Transmitter sequence to Disconnect.
Definition: dcp_spec.c:277
macros.h
Read
@ Read
Definition: statemachine.h:11
dcp_spec.h
atende
void atende()
Função handler do sinal de alarme.
Definition: dcp_spec.c:215
MAX_SIZE
#define MAX_SIZE
Definition: macros.h:12
BCC
#define BCC(a, c)
XOR entre a e c.
Definition: macros.h:37
C_I
#define C_I(r)
(0x00 0x40) Campo de Controlo - Tramas I
Definition: macros.h:35
fillFinalBuffer
int fillFinalBuffer(unsigned char *finalBuffer, unsigned char *headerBuf, unsigned char *footerBuf, int footerBufSize, unsigned char *dataBuffer, int dataSize)
Stuffs the final buffer with the Information Packet.
Definition: dcp_spec.c:257
writeCycle
int writeCycle(enum writingType type, int fd, unsigned char *buf, int bufsize)
Function used to write to fd.
Definition: dcp_spec.c:72
MAX_SIZE_AFT_STUFF
#define MAX_SIZE_AFT_STUFF
Definition: macros.h:59
initConnection
int initConnection(int *fd, char *port)
Estabelece ligação ao cabo e cria fd.
Definition: dcp_spec.c:178
statemachine.h
llclose
int llclose(int fd)
Closes the connection to the serial port.
Definition: dcp.c:141
logs.h
receiver_DISC_UA
int receiver_DISC_UA(int fd)
Receiver sequence to Disconnect.
Definition: dcp_spec.c:300
FLAG
#define FLAG
(0x7E) flag de inicio e fim
Definition: macros.h:25
failed
volatile int failed
used in the alarm handler
Definition: dcp.h:40
dcp.h
log_error
void log_error(char *arr)
Outputs a message in red.
Definition: logs.c:7
llopen
int llopen(int porta, int type)
Opens a data connection with the serial port.
Definition: dcp.c:9
TRANSMITTER
#define TRANSMITTER
Definition: macros.h:44
testSend
int testSend
Definition: dcp.c:7
readingCycle
int readingCycle(enum readingType type, int fd, unsigned char *c, unsigned char **dataBuf, int *retBufferSize)
Function to read a byte from fd.
Definition: dcp_spec.c:7
log_success
void log_success(char *arr)
Outputs a message in green.
Definition: logs.c:19
llread
int llread(int fd, unsigned char *buffer)
Reads from fd to buffer.
Definition: dcp.c:109
writeR
@ writeR
Definition: dcp_spec.h:10
readR
@ readR
Definition: dcp_spec.h:9
old_action
static struct sigaction old_action
sigaction to restore SIGALRN handler
Definition: dcp.c:6
llwrite
int llwrite(int fd, char *buffer, int lenght)
Writes the content of buffer to fd.
Definition: dcp.c:47