2
* libzvbi - Teletext packet decoder, packet 8/30
4
* Copyright (C) 2003, 2004 Michael H. Schimek
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
/* $Id: packet-830.c,v 1.4 2005/01/31 07:21:34 mschimek Exp $ */
28
#include "bcd.h" /* vbi3_bcd2dec() */
29
#include "hamm.h" /* vbi3_rev16p(), vbi3_iham8() */
30
#include "packet-830.h"
33
* @addtogroup Packet830 Teletext Packet 8/30 Decoder
35
* @brief Functions to decode Teletext packets 8/30 (ETS 300 706).
39
* @param cni CNI of type VBI3_CNI_TYPE_8301 will be stored here.
40
* @param buffer Teletext packet as defined for @c VBI3_SLICED_TELETEXT_B,
41
* i.e. 42 bytes without clock run-in and framing code.
43
* Decodes a Teletext packet 8/30 format 1 according to
44
* ETS 300 706 section 9.8.1, returning the 16 bit Country and
45
* Network Identifier in @a cni.
48
* Always @c TRUE, no error checking possible.
51
vbi3_decode_teletext_8301_cni (unsigned int * cni,
52
const uint8_t buffer[42])
55
assert (NULL != buffer);
57
*cni = vbi3_rev16p (buffer + 9);
63
* @param tme UTC time will be stored here.
64
* @param gmtoff Local time offset in seconds east of UTC is stored here,
65
* including daylight saving time, as in BSD and GNU struct tm tm_gmtoff.
66
* To get the local time of the network broadcasting this packet add
67
* @a gmtoff to @a time.
68
* @param buffer Teletext packet as defined for @c VBI3_SLICED_TELETEXT_B,
69
* i.e. 42 bytes without clock run-in and framing code.
71
* Decodes a Teletext packet 8/30 format 1 according to
72
* ETS 300 706 section 9.8.1, returning the time data.
74
* Note a few stations incorrectly transmit local time instead of UTC,
78
* @c FALSE if the buffer contained incorrectable data, in this case
79
* @a tme and @a gmtoff remain unchanged.
82
vbi3_decode_teletext_8301_local_time
85
const uint8_t buffer[42])
93
assert (NULL != gmtoff);
94
assert (NULL != buffer);
96
bcd = (+ ((buffer[12] & 15) << 16)
101
if (!vbi3_is_bcd (bcd))
104
mjd = vbi3_bcd2dec (bcd);
106
bcd = (+ (buffer[15] << 16)
111
if (vbi3_bcd_digits_greater (bcd, 0x295959))
114
utc = (bcd & 15) + ((bcd >> 4) & 15) * 10;
116
utc += (bcd & 15) * 60 + ((bcd >> 4) & 15) * 600;
118
utc += (bcd & 15) * 3600 + (bcd >> 4) * 36000;
120
if (utc >= 24 * 60 * 60)
123
*tme = (mjd - 40587) * 86400 + utc;
125
/* Local time offset in seconds east of UTC. */
127
t = (buffer[11] & 0x3E) * (15 * 60);
129
if (buffer[11] & 0x40)
132
/* 300 706 says 0x81 bits are reserved, some stations set,
133
some clear, no apparent function (no UTC/local flag anyway). */
141
* @param cni CNI of type VBI3_CNI_TYPE_8302 will be stored here.
142
* @param buffer Teletext packet as defined for @c VBI3_SLICED_TELETEXT_B,
143
* i.e. 42 bytes without clock run-in and framing code.
145
* Decodes a Teletext packet 8/30 format 2 according to
146
* ETS 300 706 section 9.8.2, returning the 16 bit Country and
147
* Network Identifier in @a cni.
150
* @c FALSE if the buffer contained incorrectable data, in this case
151
* @a cni remains unchanged.
154
vbi3_decode_teletext_8302_cni (unsigned int * cni,
155
const uint8_t buffer[42])
159
assert (NULL != cni);
160
assert (NULL != buffer);
162
b[ 7] = vbi3_unham16p (buffer + 10);
163
b[ 8] = vbi3_unham16p (buffer + 12);
164
b[10] = vbi3_unham16p (buffer + 16);
165
b[11] = vbi3_unham16p (buffer + 18);
167
if ((b[7] | b[8] | b[10] | b[11]) < 0)
170
b[ 7] = vbi3_rev8 (b[ 7]);
171
b[ 8] = vbi3_rev8 (b[ 8]);
172
b[10] = vbi3_rev8 (b[10]);
173
b[11] = vbi3_rev8 (b[11]);
175
*cni = (+ ((b[ 7] & 0x0F) << 12)
176
+ ((b[10] & 0x03) << 10)
177
+ ((b[11] & 0xC0) << 2)
185
* @param pid PDC data will be stored here.
186
* @param buffer Teletext packet as defined for @c VBI3_SLICED_TELETEXT_B,
187
* i.e. 42 bytes without clock run-in and framing code.
189
* Decodes a Teletext packet 8/30 format 2 according to
190
* ETS 300 231, storing PDC recording-control data in @a pid.
193
* @c FALSE if the buffer contained incorrectable data, in this case
194
* @a pid remains unchanged.
197
vbi3_decode_teletext_8302_pdc (vbi3_program_id * pid,
198
const uint8_t buffer[42])
204
assert (NULL != pid);
205
assert (NULL != buffer);
207
error = vbi3_unham8 (buffer[10]);
210
for (i = 7; i <= 12; ++i) {
213
t = vbi3_unham16p (buffer + i * 2 - 4);
215
b[i] = vbi3_rev8 (t);
221
pid->cni_type = VBI3_CNI_TYPE_8302;
222
pid->cni = (+ ((b[ 7] & 0x0F) << 12)
223
+ ((b[10] & 0x03) << 10)
224
+ ((b[11] & 0xC0) << 2)
228
pid->channel = VBI3_PID_CHANNEL_LCI_0 + ((b[6] >> 2) & 3);
230
pid->luf = !!(b[6] & 2);
233
pid->pcs_audio = b[7] >> 6;
235
pid->mi = !!(b[7] & 0x20);
237
pid->pil = (+ ((b[ 8] & 0x3F) << 14)
241
pid->month = VBI3_PIL_MONTH (pid->pil) - 1;
242
pid->day = VBI3_PIL_DAY (pid->pil) - 1;
243
pid->hour = VBI3_PIL_HOUR (pid->pil);
244
pid->minute = VBI3_PIL_MINUTE (pid->pil);
246
pid->length = 0; /* unknown */
250
pid->tape_delayed = FALSE;