-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLink.h
61 lines (52 loc) · 1.47 KB
/
Link.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef LINK_H
#define LINK_H
#include <linux/serial.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <termios.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include "defs.h"
#define DEFAULT_BAUDRATE B38400
#define DEFAULT_MAX_ATTEMPTS 3
#define DEFAULT_TIMEOUT 5.0
#define FLAG 0x7E
#define A 0x03
#define C_SET 0x03
#define C_UA 0x07
#define C_DISC 0x0B
#define RR 0x05
#define REJ 0x01
#define ESC 0x7D
typedef struct {
unsigned char F_BEG, df_A, df_C;
unsigned int extraPackageFieldSize; /* in bytes */
unsigned char BCC1[2];
unsigned char packageField[1];
} dataFrame;
typedef struct {
char port[20];
int baudrate; //Value of -1 means default is used
unsigned int sequenceNumber;
unsigned int timeout;
unsigned int numMaxTransmissions;
unsigned long int numTimeouts;
unsigned long long int numReceivedREJ;
unsigned long long int numRetransmittedFrames;
unsigned long long int totalDataSent;
int debugMode, wrongBCC2rate, BCC2wasWrong;
unsigned char rightBCC2[2];
} linkLayer;
linkLayer* LLayer;
struct termios oldtio,newtio;
void createNewLinkLayer(char* portname);
void createNewLinkLayerOptions(char* portname,int baudrate, unsigned int numMaxTransmissions, unsigned int timeout);
int llopen();
int llclose(int fd);
int llwrite(int fd, unsigned char* applicationPackage, int length);
int llread(int fd, unsigned char* buffer, int length);
#endif