-
Notifications
You must be signed in to change notification settings - Fork 16
/
TCPClient.h
125 lines (110 loc) · 4.49 KB
/
TCPClient.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
/**
***************************************************************************
* Description : Header for TCP command handler
* Compiler : C++
*
* Copyright (C) 2017, Peter Kwan
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and this
* permission notice and warranty disclaimer appear in supporting
* documentation, and that the name of the author not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* The author disclaims all warranties with regard to this
* software, including all implied warranties of merchantability
* and fitness. In no event shall the author be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether
* in an action of contract, negligence or other tortious action,
* arising out of or in connection with the use or performance of
* this software.
***************************************************************************
* Handle network control commands.
* Initially for Newfor subtitles but can also be used for other inserter
* control functions.
* These inserter functions follow MRG Systems' XTP620 protocol
*
* Example:
* To find out what model of inserter you are connected to, type Y.
* You will need to enable Telnet (Windows) or run nc (Linux).
* Telnet can be enabled in the "Turn Windows features on or off" settings.
* Connect to the IP address and port of your VBIT "telnet 192.168.1.2 5570"
* Type Y<enter>
* Should reply "VBIT620"
* Use CTRL-] to exit telnet
**/
#ifndef _TCPCLIENT_H_
#define _TCPCLIENT_H_
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h> /* for recv() and send() */
#include <unistd.h> /* for close() */
#endif
#include <stdint.h>
#include "pagelist.h"
#include "newfor.h"
#include "debug.h"
#include "packetsubtitle.h"
namespace vbit
{
class TCPClient
{
public:
TCPClient(Debug* debug, PacketSubtitle* subtitle, ttx::PageList* pageList);
~TCPClient();
void Handler(int clntSocket);
private:
Debug* _debug;
// Constants
static const uint8_t MAXCMD=128;
static const uint8_t RCVBUFSIZE=132; /* Size of receive buffer */
// Normal command mode
static const uint8_t MODENORMAL=0;
static const uint8_t MODESOFTELPAGEINIT=1;
// Get row count
static const uint8_t MODEGETROWCOUNT=3;
// Get a row of data
static const uint8_t MODEGETROW=4;
// Display the row
static const uint8_t MODESUBTITLEONAIR=5;
// Clear down
static const uint8_t MODESUBTITLEOFFAIR=6;
static const uint8_t MODESUBTITLEDATAHIGHNYBBLE=7;
static const uint8_t MODESUBTITLEDATALOWNYBBLE=8;
// Variables
char _cmd[MAXCMD]; // command buffer
char* _pCmd; // Pointer into the command buffer
Newfor _newfor;
int _row; // Row counter
char* _pkt; // A teletext packet (one row of VBI)
int _rowAddress; // The address of this row
/** The page address in MPPSS (hex. 10000..8FF99. Omitting trailing characters defaults to 0
* wildcard
*/
char _pageNumber[6];
ttx::PageList* _pageList; // List of pages for XTP620 commands to access
// Functions
void clearCmd(void);
void addChar(char ch, char* response);
void command(char* cmd, char* response); // Handles XPT620 commands
void DieWithError(std::string errorMessage);
/** Validate a page identity of the form mppss
* Where:
* m=1..8
* p=0..f
* s=0,,9
* and any digit can be wildcarded with *
* and trailing digits can be omitted where they will be defaulted to 0
* \param src - the page identity parameter of a P command. (only one allowed in this implementation)
* \param dest - the validated page number
* \return true if the page identity is valid
*/
bool Validate(char* dest, char* src);
};
}
#endif