test_switch.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * test_switch.c - Test program for new API
  3. *
  4. * Copyright (C) 2001 Ralph Metzler <ralph@convergence.de>
  5. * & Marcus Metzler <marcus@convergence.de>
  6. for convergence integrated media GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. */
  23. #include <sys/ioctl.h>
  24. #include <stdio.h>
  25. #include <stdint.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #include <time.h>
  30. #include <sys/poll.h>
  31. #include <linux/dvb/dmx.h>
  32. #include <linux/dvb/frontend_old.h>
  33. #include <linux/dvb/sec.h>
  34. #include <linux/dvb/video.h>
  35. int fd_frontend;
  36. int fd_sec;
  37. int fd_demuxa;
  38. int fd_demuxv;
  39. int fd_demuxtt;
  40. struct dmx_sct_filter_params sctFilterParams;
  41. struct secCommand scmd;
  42. struct secCmdSequence scmds;
  43. struct dmx_pes_filter_params pesFilterParams;
  44. struct dmx_pes_filter_params pesFilterParamsV;
  45. struct dmx_pes_filter_params pesFilterParamsA;
  46. struct dmx_pes_filter_params pesFilterParamsTT;
  47. FrontendParameters frp;
  48. int front_type;
  49. set_front(void)
  50. {
  51. fe_status_t stat = 0;
  52. int i, freq;
  53. uint32_t soff;
  54. scmds.miniCommand = SEC_MINI_NONE;
  55. scmds.numCommands = 1;
  56. scmds.commands = &scmd;
  57. soff = frp.u.qpsk.SymbolRate/16000;
  58. if (ioctl(fd_sec, SEC_SEND_SEQUENCE, &scmds) < 0)
  59. perror("setfront sec");
  60. usleep(100000);
  61. freq = frp.Frequency;
  62. while(tune_it(&frp));
  63. }
  64. set_diseqc_nb(int nr)
  65. {
  66. scmd.type=0;
  67. scmd.u.diseqc.addr = 0x10;
  68. scmd.u.diseqc.cmd = 0x38;
  69. scmd.u.diseqc.numParams = 1;
  70. scmd.u.diseqc.params[0] = 0xF0 | ((nr * 4) & 0x0F) |
  71. (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
  72. (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);
  73. }
  74. set_ttpid(ushort ttpid)
  75. {
  76. if (ttpid==0 || ttpid==0xffff || ttpid==0x1fff) {
  77. ioctl(fd_demuxtt, DMX_STOP, 0);
  78. return;
  79. }
  80. pesFilterParamsTT.pid = ttpid;
  81. pesFilterParamsTT.input = DMX_IN_FRONTEND;
  82. pesFilterParamsTT.output = DMX_OUT_DECODER;
  83. pesFilterParamsTT.pes_type = DMX_PES_TELETEXT;
  84. pesFilterParamsTT.flags = DMX_IMMEDIATE_START;
  85. if (ioctl(fd_demuxtt, DMX_SET_PES_FILTER,
  86. &pesFilterParamsTT) < 0) {
  87. printf("PID=%04x\n", ttpid);
  88. perror("set_ttpid");
  89. }
  90. }
  91. set_vpid(ushort vpid)
  92. {
  93. if (vpid==0 || vpid==0xffff || vpid==0x1fff) {
  94. ioctl(fd_demuxv, DMX_STOP, 0);
  95. return;
  96. }
  97. pesFilterParamsV.pid = vpid;
  98. pesFilterParamsV.input = DMX_IN_FRONTEND;
  99. pesFilterParamsV.output = DMX_OUT_DECODER;
  100. pesFilterParamsV.pes_type = DMX_PES_VIDEO;
  101. pesFilterParamsV.flags = DMX_IMMEDIATE_START;
  102. if (ioctl(fd_demuxv, DMX_SET_PES_FILTER,
  103. &pesFilterParamsV) < 0)
  104. perror("set_vpid");
  105. }
  106. set_apid(ushort apid)
  107. {
  108. if (apid==0 || apid==0xffff || apid==0x1fff) {
  109. ioctl(fd_demuxa, DMX_STOP, apid);
  110. return;
  111. }
  112. pesFilterParamsA.pid = apid;
  113. pesFilterParamsA.input = DMX_IN_FRONTEND;
  114. pesFilterParamsA.output = DMX_OUT_DECODER;
  115. pesFilterParamsA.pes_type = DMX_PES_AUDIO;
  116. pesFilterParamsA.flags = DMX_IMMEDIATE_START;
  117. if (ioctl(fd_demuxa, DMX_SET_PES_FILTER,
  118. &pesFilterParamsA) < 0)
  119. perror("set_apid");
  120. }
  121. int tune_it(FrontendParameters *frp)
  122. {
  123. fe_status_t stat = 0;
  124. int res;
  125. FrontendEvent event;
  126. int count = 0;
  127. struct pollfd pfd[1];
  128. if (ioctl(fd_frontend, FE_SET_FRONTEND, frp) <0)
  129. perror("setfront front");
  130. pfd[0].fd = fd_frontend;
  131. pfd[0].events = POLLIN;
  132. if (poll(pfd,1,3000)){
  133. if (pfd[0].revents & POLLIN){
  134. printf("Getting QPSK event\n");
  135. if ( ioctl(fd_frontend, FE_GET_EVENT, &event)
  136. == -EOVERFLOW){
  137. perror("qpsk get event");
  138. return -1;
  139. }
  140. printf("Received ");
  141. switch(event.type){
  142. case FE_UNEXPECTED_EV:
  143. printf("unexpected event\n");
  144. return -1;
  145. case FE_FAILURE_EV:
  146. printf("failure event\n");
  147. return -1;
  148. case FE_COMPLETION_EV:
  149. printf("completion event\n");
  150. }
  151. }
  152. }
  153. return 0;
  154. }
  155. set_tp(uint *freq, int ttk, int pol, uint srate, int dis)
  156. {
  157. if (*freq < 11700000) {
  158. frp.Frequency = (*freq - 9750000);
  159. scmds.continuousTone = SEC_TONE_OFF;
  160. } else {
  161. frp.Frequency = (*freq - 10600000);
  162. scmds.continuousTone = SEC_TONE_ON;
  163. }
  164. if (pol) scmds.voltage = SEC_VOLTAGE_18;
  165. else scmds.voltage = SEC_VOLTAGE_13;
  166. set_diseqc_nb(dis);
  167. frp.u.qpsk.SymbolRate = srate;
  168. frp.u.qpsk.FEC_inner = 0;
  169. }
  170. get_front(void)
  171. {
  172. set_vpid(0);
  173. set_apid(0);
  174. set_ttpid(0);
  175. scmds.voltage = SEC_VOLTAGE_18;
  176. scmds.miniCommand = SEC_MINI_NONE;
  177. scmds.continuousTone = SEC_TONE_OFF;
  178. scmds.numCommands=1;
  179. scmds.commands=&scmd;
  180. frp.Frequency=(12073000-10600000);
  181. frp.u.qpsk.SymbolRate=25378000;
  182. frp.u.qpsk.FEC_inner=(fe_code_rate_t)5;
  183. }
  184. void get_sect(int fd)
  185. {
  186. u_char sec[4096];
  187. int len, i;
  188. uint16_t cpid = 0;
  189. uint16_t length;
  190. struct pollfd pfd;
  191. pfd.fd = fd;
  192. pfd.events = POLLIN;
  193. while (1){
  194. if (poll(&pfd, 1, 5000) != POLLIN) {
  195. printf("not found\n");
  196. printf("Timeout\n");
  197. } else {
  198. len = read(fd, sec, 4096);
  199. length = (sec[1]& 0x0F)<<8;
  200. length |= (sec[2]& 0xFF);
  201. for (i= 0; i < length+3; i++) {
  202. printf("0x%02x ",sec[i]);
  203. if ( !((i+1)%8))
  204. printf("\n");
  205. }
  206. printf("\n");
  207. }
  208. }
  209. }
  210. int FEReadStatus(int fd, fe_status_t *stat)
  211. {
  212. int ans;
  213. if ((ans = ioctl(fd,FE_READ_STATUS,stat)) < 0) {
  214. perror("FE READ STATUS: ");
  215. return -1;
  216. }
  217. if (*stat & FE_HAS_POWER)
  218. printf("FE HAS POWER\n");
  219. if (*stat & FE_HAS_SIGNAL)
  220. printf("FE HAS SIGNAL\n");
  221. if (*stat & FE_SPECTRUM_INV)
  222. printf("QPSK SPEKTRUM INV\n");
  223. return 0;
  224. }
  225. int has_signal()
  226. {
  227. fe_status_t stat;
  228. FEReadStatus(fd_frontend, &stat);
  229. if (stat & FE_HAS_SIGNAL)
  230. return 1;
  231. else {
  232. printf("Tuning failed\n");
  233. return 0;
  234. }
  235. }
  236. main()
  237. {
  238. int freq;
  239. fd_demuxtt = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);
  240. fd_frontend = open("/dev/ost/frontend", O_RDWR);
  241. fd_sec = open("/dev/ost/sec", O_RDWR);
  242. fd_demuxa = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);
  243. fd_demuxv = open("/dev/ost/demux", O_RDWR|O_NONBLOCK);
  244. // get_front();
  245. // set_vpid(0x7d0);
  246. // set_apid(0x7d2);
  247. // set_ttpid(0);
  248. // freq = 12073000;
  249. // set_tp(&freq, 1, 1, 25378000, 3);
  250. // set_diseqc_nb(dis);
  251. scmds.voltage = SEC_VOLTAGE_18;
  252. // scmds.voltage = SEC_VOLTAGE_13;
  253. scmds.miniCommand = SEC_MINI_NONE;
  254. scmds.continuousTone = SEC_TONE_OFF;
  255. scmds.numCommands=1;
  256. scmds.commands=&scmd;
  257. frp.Frequency = (12073000 - 10600000);
  258. // frp.Frequency = (11975000 - 10600000);
  259. scmds.continuousTone = SEC_TONE_ON;
  260. frp.u.qpsk.SymbolRate = 25378000;
  261. // frp.u.qpsk.SymbolRate = 27500000;
  262. // frp.u.qpsk.FEC_inner = FEC_AUTO;
  263. frp.u.qpsk.FEC_inner = (fe_code_rate_t)5;
  264. scmd.type=0;
  265. scmd.u.diseqc.addr = 0x10;
  266. scmd.u.diseqc.cmd = 0x38;
  267. scmd.u.diseqc.numParams = 1;
  268. scmd.u.diseqc.params[0] = 0xF0 | ((3 * 4) & 0x0F) |
  269. (scmds.continuousTone == SEC_TONE_ON ? 1 : 0) |
  270. (scmds.voltage==SEC_VOLTAGE_18 ? 2 : 0);
  271. if (ioctl(fd_sec, SEC_SEND_SEQUENCE, &scmds) < 0)
  272. perror("setfront sec");
  273. while(tune_it(&frp));
  274. /*
  275. if ((fd_demuxa=open("/dev/ost/demux", O_RDWR|O_NONBLOCK))
  276. < 0){
  277. perror("DEMUX DEVICE: ");
  278. return -1;
  279. }
  280. memset(&sctFilterParams.filter, 0, sizeof(struct dmx_filter));
  281. sctFilterParams.pid = 0x1fff;
  282. sctFilterParams.filter.filter[0] = 0x00;
  283. sctFilterParams.filter.mask[0] = 0x00;
  284. sctFilterParams.timeout = 0;
  285. sctFilterParams.flags = DMX_IMMEDIATE_START;
  286. if (ioctl(fd_demuxa, DMX_SET_FILTER, &sctFilterParams) < 0)
  287. perror("DMX SET FILTER:");
  288. get_sect(fd_demuxa);
  289. */
  290. pesFilterParamsA.pid = 0x1fff;
  291. pesFilterParamsA.input = DMX_IN_FRONTEND;
  292. pesFilterParamsA.output = DMX_OUT_TS_TAP;
  293. pesFilterParamsA.pes_type = DMX_PES_OTHER;
  294. pesFilterParamsA.flags = DMX_IMMEDIATE_START;
  295. if (ioctl(fd_demuxa, DMX_SET_PES_FILTER,
  296. &pesFilterParamsA) < 0)
  297. perror("set_apid");
  298. while(1);
  299. }