trunk 20080912
[gitenigma.git] / lib / system / info.cpp
blobf13539fe8e5910f1191a566494f07896598bbf0b
1 #include <lib/system/info.h>
3 #include <lib/base/estring.h>
4 #include <lib/system/init.h>
5 #include <lib/system/init_num.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <lib/dvb/frontend.h>
13 #include <errno.h>
14 #if HAVE_DVB_API_VERSION == 3
15 #include <tuxbox.h>
16 #endif
18 eSystemInfo *eSystemInfo::instance;
20 eSystemInfo::eSystemInfo()
21 :hashdd(0), hasci(0), hasrfmod(0), haslcd(0), hasnetwork(1)
22 ,haskeyboard(0) ,canmeasurelnbcurrent(0), hasnegfilter(0)
23 ,canupdateTransponder(0), canshutdown(1), canrecordts(0)
24 ,alphaincrement(10), hasstandbywakeuptimer(0), cantimeshift(0)
25 ,hasscartswitch(1)
27 instance=this;
28 #if HAVE_DVB_API_VERSION == 3
29 int fd=::open(DEMOD_DEV, O_RDONLY);
30 fetype = feUnknown;
31 if (fd>=0)
33 dvb_frontend_info info;
34 if ( ::ioctl(fd, FE_GET_INFO, &info) >= 0 )
36 switch (info.type)
38 case FE_QPSK:
39 fetype = feSatellite;
40 break;
41 case FE_QAM:
42 fetype = feCable;
43 break;
44 default:
45 case FE_OFDM:
46 fetype = feTerrestrial;
47 break;
50 else
51 eDebug("FE_GET_INFO failed (%m)");
52 ::close (fd);
54 else
55 eDebug("open demod failed (%m)");
56 std::set<int> caids;
57 hasnegfilter=1;
58 switch (tuxbox_get_submodel())
60 case TUXBOX_SUBMODEL_DREAMBOX_DM7000:
61 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
62 canupdateTransponder = canrecordts = hashdd =
63 haslcd = canmeasurelnbcurrent =
64 hasci = 1;
65 hwtype = DM7000;
66 // caids.insert(0x4a70);
67 midstr="5";
68 helpstr="dreambox";
69 modelstr="DM7000";
70 cpustr="STB04500, 252MHz";
71 break;
72 case TUXBOX_SUBMODEL_DBOX2:
73 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
74 caids.insert(0x1702);
75 caids.insert(0x1722);
76 caids.insert(0x1762);
77 canrecordts=1;
78 hasstandbywakeuptimer=haslcd=1;
79 helpstr="dbox2";
80 modelstr="d-Box 2";
81 cpustr="XPC823, 66MHz";
82 switch ( tuxbox_get_vendor() )
84 case TUXBOX_VENDOR_NOKIA:
85 hwtype = dbox2Nokia;
86 midstr="1";
87 manufactstr="Nokia";
88 break;
89 case TUXBOX_VENDOR_PHILIPS:
90 midstr="2";
91 hwtype = dbox2Philips;
92 manufactstr="Philips";
93 break;
94 case TUXBOX_VENDOR_SAGEM:
95 midstr="3";
96 hwtype = dbox2Sagem;
97 manufactstr="Sagem";
98 break;
99 default:
100 hwtype = Unknown;
102 break;
103 default:
104 hwtype = Unknown;
105 break;
107 #else
108 int mid = atoi(getInfo("mID").c_str());
110 switch (mid)
112 case 5 ... 7:
113 case 9:
114 case 11:
115 case 12:
116 manufactstr="Dream-Multimedia-TV";
117 helpstr="dreambox";
118 canupdateTransponder=haskeyboard=1;
119 caids.insert(0x4a70);
120 switch(mid)
122 case 5:
123 midstr="5";
124 modelstr="DM7000";
125 cpustr="STB04500, 252MHz";
126 hashdd = haslcd = canmeasurelnbcurrent = hasci
127 = canrecordts = cantimeshift = 1;
128 hwtype = DM7000;
129 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
131 // check if new FP Firmware is avail...
132 int fd = open("/dev/dbox/fp0", O_RDWR);
133 if ( fd >=0)
135 #define FP_IOCTL_GET_ID 0
136 int ret = ::ioctl(fd,FP_IOCTL_GET_ID);
137 if ( ret < 0 )
138 eDebug("old fp driver.. no support for wakeup timer");
139 else if ( ret == 0 )
140 eDebug("old fp firmware... no support for wakeup timer");
141 else
142 hasstandbywakeuptimer=1;
143 close(fd);
146 break;
147 case 6:
148 midstr="6";
149 cpustr="STBx25xx, 252MHz";
150 alphaincrement=25;
151 canshutdown=0;
152 hasci = 2;
153 hwtype = getInfo("type", true) == "DM5600" ? DM5600 : DM5620;
154 if ( hwtype == DM5600 )
156 defaulttimertype=ePlaylistEntry::SwitchTimerEntry;
157 hasnetwork=0;
158 modelstr="DM5600";
160 else
162 modelstr="DM5620";
163 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
165 break;
166 case 7:
167 midstr="7";
168 cpustr="STBx25xx, 252MHz";
169 modelstr="DM500";
170 alphaincrement=25;
171 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
172 canshutdown=canrecordts=hasscartswitch=0;
173 hwtype = DM500;
174 break;
175 case 9:
177 midstr="9";
178 modelstr="DM7020";
179 cpustr="STB04500, 252MHz";
180 hasrfmod = hashdd = haslcd = hasci
181 = canrecordts = hasstandbywakeuptimer = cantimeshift = 1;
182 // check if the box revision is new enough to measure
183 // lnb power with > 13V ( revisions with lnbp21 can this )
184 int fd = open("/dev/dbox/fp0", O_RDWR);
185 if ( fd >=0 )
187 if ( ::ioctl( fd, 0x100, 0 ) == 0 )
188 canmeasurelnbcurrent=1;
189 else
190 canmeasurelnbcurrent=2;
191 close(fd);
193 hwtype = DM7020;
194 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
195 break;
197 case 11:
199 alphaincrement=25;
200 midstr="11";
201 modelstr="DM600PVR";
202 cpustr="STBx25xx, 252MHz";
203 hashdd = canrecordts = cantimeshift = 1;
204 hasscartswitch = 0;
205 hwtype = DM600PVR;
206 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recDVR;
207 break;
209 case 12:
211 alphaincrement=25;
212 midstr="12";
213 modelstr="DM500PLUS";
214 cpustr="STBx25xx, 252MHz";
215 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
216 canrecordts=hasscartswitch=0;
217 hwtype = DM500PLUS;
218 break;
221 break;
222 case 1 ... 3:
223 modelstr="d-Box 2";
224 helpstr="dbox2";
225 cpustr="XPC823, 66MHz";
226 caids.insert(0x1702);
227 caids.insert(0x1722);
228 caids.insert(0x1762);
229 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
230 hasstandbywakeuptimer=haslcd=1;
231 switch ( mid )
233 case 1:
234 manufactstr="Nokia";
235 midstr="1";
236 hwtype = dbox2Nokia;
237 break;
238 case 2:
239 manufactstr="Philips";
240 midstr="2";
241 hwtype = dbox2Philips;
242 break;
243 case 3:
244 manufactstr="Sagem";
245 midstr="3";
246 hwtype = dbox2Sagem;
247 break;
248 default:
249 break;
251 break;
252 case 8:
253 manufactstr="Triax";
254 helpstr="dreambox";
255 midstr="8";
256 cpustr="STBx25xx, 252MHz";
257 modelstr="DVB 272S";
258 alphaincrement=25;
259 defaulttimertype=ePlaylistEntry::RecTimerEntry|ePlaylistEntry::recNgrab;
260 canshutdown=0;
261 haskeyboard=canupdateTransponder=1;
262 hwtype = TR_DVB272S;
263 caids.insert(0x4a70);
264 hasci=2;
265 break;
266 default:
267 break;
269 int fd = open ("/dev/rfmod0", O_RDWR);
270 if ( fd >= 0 )
272 hasrfmod=1;
273 close(fd);
275 fd = open("/dev/dvb/card0/demux0", O_RDWR);
276 if ( fd >=0 )
278 if ( ::ioctl( fd, DMX_SET_NEGFILTER_MASK, 0 ) >= 0 )
279 hasnegfilter=1;
280 close(fd);
282 if ( hwtype < DM7000 )
284 switch (atoi(getInfo("fe").c_str()))
286 case 0: // DBOX_FE_CABLE
287 fetype=feCable;
288 break;
289 case 1: // DBOX_FE_SATELLITE
290 fetype=feSatellite;
291 break;
292 default:
293 fetype=feSatellite;
296 else
298 fetype = feUnknown;
299 int fd=::open(DEMOD_DEV, O_RDONLY);
300 if (fd>=0)
302 FrontendInfo info;
303 fetype = feSatellite; // default
304 if ( ::ioctl(fd, FE_GET_INFO, &info) >= 0 )
306 switch (info.type)
308 case FE_QPSK:
309 fetype = feSatellite;
310 break;
311 case FE_QAM:
312 fetype = feCable;
313 break;
314 case FE_OFDM:
315 fetype = feTerrestrial;
316 break;
319 else
320 eDebug("FE_GET_INFO failed (%m)");
321 ::close (fd);
324 #endif
327 #if HAVE_DVB_API_VERSION < 3
328 eString eSystemInfo::getInfo(const char *info, bool dreambox)
330 FILE *f=0;
331 if ( dreambox )
332 f=fopen("/proc/bus/dreambox", "rt");
333 else
334 f=fopen("/proc/bus/dbox", "rt");
335 if (!f)
336 return "";
337 eString result;
338 while (1)
340 char buffer[128];
341 if (!fgets(buffer, 128, f))
342 break;
343 if (strlen(buffer))
344 buffer[strlen(buffer)-1]=0;
345 if ((!strncmp(buffer, info, strlen(info)) && (buffer[strlen(info)]=='=')))
347 int i = strlen(info)+1;
348 result = eString(buffer).mid(i, strlen(buffer)-i);
349 break;
352 fclose(f);
353 return result;
355 #endif
357 eAutoInitP0<eSystemInfo> init_info(eAutoInitNumbers::sysinfo, "SystemInfo");