forked from peterkvt80/vbit2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.h
172 lines (144 loc) · 4.85 KB
/
packet.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef _PACKET_H_
#define _PACKET_H_
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <ctime>
#include "tables.h"
#include "hamm-tables.h"
#include <cassert>
#include "ttxpage.h"
/**
* Teletext packet.
* Deals with teletext packets including header, text rows, enhanced packets, service packets and parity
*/
#define PACKETSIZE 45
namespace vbit
{
class Packet
{
public:
/** Default constructor */
Packet();
/** char constructor */
Packet(char *val);
/** string constructor */
Packet(std::string val);
/** row constructor */
Packet(int mag, int row, std::string val);
/** Default destructor */
virtual ~Packet();
inline char* Get_packet() { return _packet; }
/** Set _packet
* \param *val New value to set
*/
void Set_packet(char *val);
// this is a raw copy of 40 bytes for pre-formatted packets. use with caution!
void SetPacketRaw(char *val);
/** SetPacketText
* Copy the supplied text into the text part of the packet (last 40 bytes)
* \param val New value to set
*/
void SetPacketText(std::string val);
/** PacketQuiet
* Make this packet all 0
*/
void PacketQuiet();
/** tx
* @return Packet in transmission format.
* There are one or two things that can affect the format.
* We create transmission ready packets of 45 bytes.
* raspi-teletext does not use the clock run and framing code in so we skip the first three bytes.
* The endian depends on the hardware attached.
* Sometimes we need to reverse the bit order
*
*/
char* tx(bool reverse=false);
/** SetMRAG
* Sets the first five bytes of the packet
* Namely Two clock run in, one framing code, and two for magazine/row address group
* CRI|CRI|FC|MRAG
*/
void SetMRAG(uint8_t mag, uint8_t row);
/** Header
* Sets everything except the caption
* @param mag 0..7 (where 0 is mag 8)
* @param page number 00..ff
* @param subcode (16 bit hex code as in tti file)
* @param control C bits
*/
void Header(unsigned char mag, unsigned char page, unsigned int subcode, unsigned int control);
/** HeaderText
* Sets last 32 bytes. This is the caption part
* @param val String of exactly 32 characters.
*/
void HeaderText(std::string val);
/** Parity
* Sets the parity of the bytes starting from offset
* @param offset 5 (default) for normal text rows, 13 for headers
*/
void Parity(uint8_t offset=5);
/** IsHeader
* Transmission rule: After a header packet, wait at least one field before transmitting rows.
* @return true if the last packet out was a header packet.
*/
bool IsHeader(){return _isHeader;};
/** Create a Fastext packet
* Requires a list of six links
* @param links Array of six link values (0x100 to 0x8FF)
* @param mag - Magazine number
*
*/
void Fastext(int* links, int mag);
/**
* @return The current row number
*/
int GetRow(){return _row;};
/**
* @return The current page number
*/
int GetPage(){return _page;};
/**
* @brief Same as the row constructor, except it doesn't construct
* @param mag - Magazine number 0..7 where 0 is magazine 8
* @param row - Row 0..31
* @param val - The contents of the row text (40 characters)
* @param coding -
*/
void SetRow(int mag, int row, std::string val, PageCoding coding);
void Dump();
protected:
private:
char _packet[46]; // 45 byte packet with room for a null terminator
bool _isHeader; //<! True if the packet is a header
uint8_t _mag;//<! The magazine number this packet belongs to 0..7 where 0 is maazine 8
uint32_t _page;//<! The page number this packet belongs to 00 to ff
uint8_t _row; //<! Row number 0 to 31
PageCoding _coding; // packet coding
bool get_offset_time(char* str);
bool get_net(char* str);
bool get_time(char* str);
/** Hamming 24/18
* The incoming triplet should be packed 18 bits of an int 32 representing D1..D18
* The int is repacked with parity bits
*/
void SetTriplet(int ix, int triplet);
/**
* @ingroup Error
* @param p A Hamming 24/18 protected 24 bit word will be stored here,
* last significant byte first, lsb first transmitted.
* @param c Integer between 0 ... 1 << 18 - 1.
*
* Encodes an 18 bit word with Hamming 24/18 protection
* as specified in ETS 300 706, Section 8.3.
*
* @since 0.2.27
*/
void vbi_ham24p(uint8_t * p, unsigned int c);
#ifdef RASPBIAN
bool get_temp(char* str);
#endif
};
}
#endif // _PACKET_H_