forked from peterkvt80/vbit2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newfor.cpp
135 lines (113 loc) · 3.69 KB
/
newfor.cpp
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
/** Newfor.cpp */
/** @file newfor.c
* @brief Softel Newfor subtitles for VBIT2.
* A TCP port 5570 on VBIT accepts newfor subtitling commands.
* The main purpose is to play out pre-recorded subtititles.
* You can also play out subtitles from a video server or
* bridged from another subtitles source such as through a DTP600.
* or accept any industry standard Newfor source.
*/
#include "newfor.h"
// @todo These will be converted to member variables
// bufferpacket packetCache[1]; // Incoming rows are cached here, and transferred to subtitleBuffer when OnAir
// Packet Subtitles are stored here
// uint8_t subtitleCache [SUBTITLEPACKETCOUNT][PACKETSIZE]; /// Storage for 8 packets, 45 bytes per packet. (for packetCache)
static uint8_t _page; /// Page number (in hex). This is set by Page Init
static uint8_t _rowcount; /// Number of rows in this subtitle
// static char packet[PACKETSIZE];
using namespace vbit;
// This is not so pretty. @todo Factor this out of TCPClient
static int
vbi_unham8 (unsigned int c)
{
return _vbi_hamm8_inv[(uint8_t) c];
}
Newfor::Newfor(PacketSubtitle* subtitle) :
_subtitle(subtitle)
{
ttxpage.SetSubCode(0);
}
Newfor::~Newfor()
{
}
/** initNu4
* @detail Initialise the buffers used by Newfor
*/
//void InitNu4()
//{
// bufferInit(packetCache ,(char*)subtitleCache ,SUBTITLEPACKETCOUNT);
//}
/**
* @detail Expect four characters
* 1: Ham 0 (always 0x15)
* 2: Page number hundreds hammed. 1..8
* 3: Page number tens hammed
* Although it says HTU, in keeping with the standard we will work in hex.
* @return The decoded page number
*/
int Newfor::SoftelPageInit(char* cmd)
{
int page=0;
int n;
// Useless leading 0
n=vbi_unham8(cmd[1]);
if (n<0) return 0x900; // @todo This is an error.
// Hundreds
n=vbi_unham8(cmd[2]);
if (n<1 || n>8) return 0x901;
page=n*0x100;
// tens (hex allowed!)
n=vbi_unham8(cmd[3]);
if (n<0 || n>0x0f) return 0x902;
page+=n*0x10;
// units
n=vbi_unham8(cmd[4]);
if (n<0 || n>0x0f) return 0x903;
page+=n;
_page=page;
ttxpage.SetPageNumber(page*0x100);
return page;
}
void Newfor::SubtitleOnair(char* response)
{
// std::cerr << "[Newfor::SubtitleOnair] page=" << std::hex << ttxpage.GetPageNumber() << std::dec << std::endl;
strcpy(response,"Response not implemented, sorry\n");
// Send the page to the subtitle object in the service thread, then clear the lines.
_subtitle->SendSubtitle(&ttxpage);
for (int i=0;i<24;i++) // Some broadcasters sent the subs out more than once. We don't.
{
ttxpage.SetRow(i," ");
}
}
void Newfor::SubtitleOffair()
{
//std::cerr << "[Newfor;:SubtitleOffair]" << std::endl;
_subtitle->SendSubtitle(&ttxpage); // OnAir will already have cleared out these lines so just send the page again
}
/**
* @return Row count 1..7, or 0 if invalid
* @param cmd - The subtitle row count comes as a hammed digit.
*/
int Newfor::GetRowCount(char* cmd)
{
int n=vbi_unham8(cmd[1]);
if (n>7)
n=0;
_rowcount=n;
return n;
}
/**
* @brief Decode the rowaddress and row packet part of a Type 2 message.
* @param mag - This is irrelevant as mag is set up in a Type 1 message
* @param row - The row number on which to display the subtitle
* @param cmd - The row text
* @brief Save a row of data when a Newfor command is completed
*/
void Newfor::saveSubtitleRow(uint8_t mag, uint8_t row, char* cmd)
{
(void)mag; // temporary silence error about unused parameter
// What @todo about the mag? This needs to be decoded and passed on
// std::cerr << "[Newfor::saveSubtitleRow] cmd=" << cmd << std::endl;
if (cmd[0]==0) cmd[0]='?'; // @todo Temporary measure to defeat null strings (this will inevitably multiply problems!)
ttxpage.SetRow(row, cmd);
}