plptools
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#ifndef _packet_h
22#define _packet_h
23
24#include "config.h"
25#include <stdio.h>
26#include <pthread.h>
27
28#include "bufferstore.h"
29#include "bufferarray.h"
30
31extern "C" {
32 static void *pump_run(void *);
33}
34
35class Link;
36
37class packet
38{
39public:
40 packet(const char *fname, int baud, Link *_link, unsigned short verbose, const int cancellationFd);
41 ~packet();
42
46 void send(bufferStore &b);
47
48 void setEpoc(bool);
49 void setVerbose(short int);
50 short int getVerbose();
51 int getSpeed();
52 bool linkFailed();
53 void reset();
54
55private:
56 friend void * pump_run(void *);
57
58 inline void addToCrc(unsigned char a, unsigned short *crc) {
59 *crc = (*crc << 8) ^ crc_table[((*crc >> 8) ^ a) & 0xff];
60 }
61
62 void findSync();
63 void opByte(unsigned char a);
64 void opCByte(unsigned char a, unsigned short *crc);
65 void realWrite();
66 void internalReset();
67
69 pthread_t datapump;
70 pthread_t thisThread;
71 unsigned int crc_table[256];
72
73 unsigned short crcOut;
74 unsigned short crcIn;
75 unsigned short receivedCRC;
76 unsigned short inCRCstate;
77
78 unsigned char *inBuffer;
80 int inRead;
81
82 unsigned char *outBuffer;
85
88
92 int fd;
96 short int verbose;
97 bool esc;
99 bool isEPOC;
101
102 char *devname;
103 int baud;
104
105 const int cancellationFd;
106};
107
108#endif
An array of bufferStores.
Definition: bufferarray.h:31
A generic container for an array of bytes.
Definition: bufferstore.h:37
Definition: packet.h:38
unsigned char * inBuffer
Definition: packet.h:78
Link * theLINK
Definition: packet.h:68
bool esc
Definition: packet.h:97
int inWrite
Definition: packet.h:79
unsigned int crc_table[256]
Definition: packet.h:71
int lastSYN
Definition: packet.h:87
unsigned short receivedCRC
Definition: packet.h:75
int getSpeed()
Definition: packet.cc:293
~packet()
Definition: packet.cc:211
bufferStore rcv
Definition: packet.h:90
void send(bufferStore &b)
Send a buffer out to serial line.
Definition: packet.cc:299
int foundSync
Definition: packet.h:91
friend void * pump_run(void *)
Definition: packet.cc:70
void setEpoc(bool)
Definition: packet.cc:287
bool isEPOC
Definition: packet.h:99
void internalReset()
Definition: packet.cc:242
bool linkFailed()
Definition: packet.cc:486
int baud
Definition: packet.h:103
int outWrite
Definition: packet.h:83
int fd
Definition: packet.h:92
bufferArray inQueue
Definition: packet.h:89
unsigned short crcOut
Definition: packet.h:73
int inRead
Definition: packet.h:80
pthread_t datapump
Definition: packet.h:69
void reset()
Definition: packet.cc:225
unsigned char * outBuffer
Definition: packet.h:82
pthread_t thisThread
Definition: packet.h:70
int startPkt
Definition: packet.h:86
unsigned short inCRCstate
Definition: packet.h:76
int serialStatus
Definition: packet.h:93
bool justStarted
Definition: packet.h:100
void setVerbose(short int)
Definition: packet.cc:281
bool lastFatal
Definition: packet.h:98
void realWrite()
Definition: packet.cc:362
short int getVerbose()
Definition: packet.cc:275
const int cancellationFd
Definition: packet.h:105
int outRead
Definition: packet.h:84
void opByte(unsigned char a)
Definition: packet.cc:343
short int verbose
Definition: packet.h:96
int baud_index
Definition: packet.h:94
void opCByte(unsigned char a, unsigned short *crc)
Definition: packet.cc:352
void findSync()
Definition: packet.cc:375
unsigned short crcIn
Definition: packet.h:74
void addToCrc(unsigned char a, unsigned short *crc)
Definition: packet.h:58
int realBaud
Definition: packet.h:95
char * devname
Definition: packet.h:102
static void * pump_run(void *)
Definition: packet.cc:70
static rfsv * a
Definition: main.cc:53