OSDN Git Service

15c7641ebf90c81966a18eb657e3dc96947b7d4d
[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         int i = 0;
49         time_t tot;
50
51         /* TOT */
52         len = parseTOThead(ptr, &toth);
53         ptr += len;
54         loop_len = toth.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
55
56         tot = parseMJD( toth.JST_time );
57         printf("TOT diff:%d[秒] %s",
58                 (int)difftime( time(NULL), tot ), ctime(&tot));
59         //ptm = localtime(time(NULL));
60 /*
61         desc_len = toth.descriptors_loop_length;
62         while(desc_len > 0) {
63                 len = parseTOTdesc(ptr, &totd);
64                 ptr += len;
65                 desc_len -= len;
66         }
67 */
68         return;
69 }
70