OSDN Git Service

first implementation of restore
[rec10/rec10-git.git] / epgdump / tot.c
1 // -*- tab-width:4 -*-
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "tot.h"
8 #include "ts_ctl.h"
9
10 int parseTOThead(unsigned char *data, TOThead *toth) {
11         int boff = 0;
12
13         memset(toth, 0, sizeof(TOThead));
14
15         toth->table_id = getBit(data, &boff, 8);
16         toth->section_syntax_indicator = getBit(data, &boff, 1);
17         toth->reserved_future_use1 = getBit(data, &boff, 1);
18         toth->reserved1 = getBit(data, &boff, 2);
19         toth->section_length = getBit(data, &boff, 12);
20         memcpy(toth->JST_time, data + boff / 8, 5);
21         boff += 40;
22         // toth->JST_time = getBit(data, &boff, 40);
23         toth->reserved2 = getBit(data, &boff, 4);
24         toth->descriptors_loop_length = getBit(data, &boff, 12);
25
26         return 10;
27 }
28
29 int parseTOTdesc(unsigned char *data, TOTdesc *totd) {
30         int boff = 0;
31
32         memset(totd, 0, sizeof(TOTdesc));
33
34         totd->descriptor_tag = getBit(data, &boff, 8);
35         totd->descriptor_length = getBit(data, &boff, 8);
36
37         return totd->descriptor_length + 2;
38 }
39
40 void dumpTOT(unsigned char *ptr)
41 {
42         TOThead  toth;
43         TOTdesc  totd;
44
45         int len = 0;
46         int loop_len = 0;
47         int desc_len = 0;
48         time_t tot;
49
50         /* TOT */
51         len = parseTOThead(ptr, &toth);
52         ptr += len;
53         loop_len = toth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
54
55         tot = parseMJD( toth.JST_time );
56         printf("TOT diff:%d[秒] %s",
57                 (int)difftime( time(NULL), tot ), ctime(&tot));
58         //ptm = localtime(time(NULL));
59 /*
60         desc_len = toth.descriptors_loop_length;
61         while(desc_len > 0) {
62                 len = parseTOTdesc(ptr, &totd);
63                 ptr += len;
64                 desc_len -= len;
65         }
66 */
67         return;
68 }
69