1 | /*
|
---|
2 | * Samo's SA4250HD firewire channel changer by majoridiot
|
---|
3 | *
|
---|
4 | * requires: libavc1394-dev libraw1394-dev
|
---|
5 | *
|
---|
6 | * compile with: gcc -o sa4250_ch sa4250_ch.c -lrom1394 -lavc1394 -lraw1394
|
---|
7 | *
|
---|
8 | * based on mythtv source code and
|
---|
9 | *
|
---|
10 | * sa3250ch - an external channel changer for SA3250HD Tuner
|
---|
11 | * Based off 6200ch.c by Stacey D. Son
|
---|
12 | *
|
---|
13 | * Copyright 2004,2005 by Stacey D. Son <mythdev@son.org>
|
---|
14 | * Copyright 2005 Matt Porter <mporter@kernel.crashing.org>
|
---|
15 | * Portions Copyright 2006 Chris Ingrassia <chris@spicecoffee.org> (SA4200 and Single-digit command mode)
|
---|
16 | *
|
---|
17 | * This program is free software; you can redistribute it and/or modify
|
---|
18 | * it under the terms of the GNU General Public License as published by
|
---|
19 | * the Free Software Foundation; either version 2 of the License, or
|
---|
20 | * (at your option) any later version.
|
---|
21 | *
|
---|
22 | * This program is distributed in the hope that it will be useful,
|
---|
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
25 | * GNU General Public License for more details.
|
---|
26 | *
|
---|
27 | * You should have received a copy of the GNU General Public License
|
---|
28 | * along with this program; if not, write to the Free Software Foundation,
|
---|
29 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include <libavc1394/rom1394.h>
|
---|
33 | #include <libavc1394/avc1394.h>
|
---|
34 | #include <libraw1394/raw1394.h>
|
---|
35 | #include <sys/types.h>
|
---|
36 | #include <stdio.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <string.h>
|
---|
40 |
|
---|
41 | /* SA42xxHD IDs */
|
---|
42 | #define SA4200HD_VENDOR_ID1 0x000014f8
|
---|
43 | #define SA4200HD_MODEL_ID1 0x00001072
|
---|
44 | #define SA4250HD_VENDOR_ID1 0x00001ac3 /* samo's stb */
|
---|
45 | #define SA4250HD_MODEL_ID1 0x000010cc /* samo's stb */
|
---|
46 | #define SA4250HDC_VENDOR_ID1 0x00001bd7
|
---|
47 | #define SA4250HDC_MODEL_ID1 0x0000206c
|
---|
48 | #define SA8300HD_VENDOR_ID1 0x000022ce
|
---|
49 | #define SA8300HD_MODEL_ID1 0x0000206c
|
---|
50 |
|
---|
51 | /* add additional vendor and model id's here- addition needed to if statement starting @ line 134 below */
|
---|
52 |
|
---|
53 | #define AVC1394_SA3250_COMMAND_CHANNEL 0x000007c00
|
---|
54 | #define AVC1394_SA3250_OPERAND_KEY_PRESS 0xe7
|
---|
55 | #define AVC1394_SA3250_OPERAND_KEY_RELEASE 0x67
|
---|
56 |
|
---|
57 | #define CTL_CMD0 AVC1394_CTYPE_CONTROL | AVC1394_SUBUNIT_TYPE_PANEL | \
|
---|
58 | AVC1394_SUBUNIT_ID_0 | AVC1394_SA3250_COMMAND_CHANNEL
|
---|
59 | #define CTL_CMD1 (0x04 << 24)
|
---|
60 | #define CTL_CMD2 0xff000000
|
---|
61 |
|
---|
62 | #define STARTING_NODE 0
|
---|
63 |
|
---|
64 | void usage()
|
---|
65 | {
|
---|
66 | fprintf(stderr, "Usage: sa_ch [-v] <channel_num>\n");
|
---|
67 | fprintf(stderr, " -v : Verbose Mode\n");
|
---|
68 | exit(1);
|
---|
69 | }
|
---|
70 |
|
---|
71 | int main (int argc, char *argv[])
|
---|
72 | {
|
---|
73 | rom1394_directory dir;
|
---|
74 | int device = -1;
|
---|
75 | int single = 0;
|
---|
76 | int i;
|
---|
77 | int verbose = 0;
|
---|
78 | int dig[3];
|
---|
79 | int chn = 708;
|
---|
80 |
|
---|
81 | if (argc < 2)
|
---|
82 | usage();
|
---|
83 |
|
---|
84 | for(i = 1; i < argc; ++i) {
|
---|
85 | if ((argv[i][0] == '-') && (strlen(argv[i]) > 1)) {
|
---|
86 | switch(argv[i][1]) {
|
---|
87 | case 'v':
|
---|
88 | verbose = 1;
|
---|
89 | break;
|
---|
90 | default:
|
---|
91 | fprintf(stderr, "WARNING: Unknown option \'%c\', ignoring", argv[i][1]);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | else {
|
---|
95 | chn = atoi(argv[i]);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | #ifdef RAW1394_V_0_8
|
---|
100 | raw1394handle_t handle = raw1394_get_handle();
|
---|
101 | #else
|
---|
102 | raw1394handle_t handle = raw1394_new_handle();
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | if (!handle) {
|
---|
106 | if (!errno) {
|
---|
107 | fprintf(stderr, "Not Compatible!\n");
|
---|
108 | } else {
|
---|
109 | perror("Couldn't get 1394 handle");
|
---|
110 | fprintf(stderr, "Is ieee1394, driver, and raw1394 loaded? Are /dev/raw1394 permissions set correctly?\n");
|
---|
111 | }
|
---|
112 | exit(1);
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (raw1394_set_port(handle, 0) < 0) {
|
---|
116 | perror("ERROR-- could not set port");
|
---|
117 | raw1394_destroy_handle(handle);
|
---|
118 | exit(1);
|
---|
119 | }
|
---|
120 |
|
---|
121 | int nc = raw1394_get_nodecount(handle);
|
---|
122 | for (i=STARTING_NODE; i < nc; ++i) {
|
---|
123 | if (rom1394_get_directory(handle, i, &dir) < 0) {
|
---|
124 | fprintf(stderr,"ERROR reading config rom directory for node %d\n", i);
|
---|
125 | raw1394_destroy_handle(handle);
|
---|
126 | exit(1);
|
---|
127 | }
|
---|
128 |
|
---|
129 | if (verbose)
|
---|
130 | printf("node %d: vendor_id = 0x%08x model_id = 0x%08x\n",
|
---|
131 | i, dir.vendor_id, dir.model_id);
|
---|
132 |
|
---|
133 | /* add new vendor and model ids to if stanza below */
|
---|
134 |
|
---|
135 | if ( ((dir.vendor_id == SA4250HDC_VENDOR_ID1) &&
|
---|
136 | (dir.model_id == SA4250HDC_MODEL_ID1)) ||
|
---|
137 | ((dir.vendor_id == SA4250HD_VENDOR_ID1) &&
|
---|
138 | (dir.model_id == SA4250HD_MODEL_ID1)) ||
|
---|
139 | ((dir.vendor_id == SA4200HD_VENDOR_ID1) &&
|
---|
140 | (dir.model_id == SA4200HD_MODEL_ID1)) ||
|
---|
141 | ((dir.vendor_id == SA8300HD_VENDOR_ID1) ||
|
---|
142 | (dir.model_id == SA8300HD_MODEL_ID1)) ) {
|
---|
143 | device = i;
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | if (device == -1) {
|
---|
149 | fprintf(stderr, "Could not find SA42XXHD on the 1394 bus!\n");
|
---|
150 | fprintf(stderr, "Try running again with -v and check source code for matching Vendor ID and Model ID-\n");
|
---|
151 | fprintf(stderr, "Add if necessary and recompile.\n");
|
---|
152 | raw1394_destroy_handle(handle);
|
---|
153 | exit(1);
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (verbose)
|
---|
157 | printf("Device acquired on node %d\n", device);
|
---|
158 | printf("Changing channel %d\n", chn);
|
---|
159 |
|
---|
160 | quadlet_t cmd[3] =
|
---|
161 | {
|
---|
162 | CTL_CMD0 | AVC1394_SA3250_OPERAND_KEY_PRESS,
|
---|
163 | CTL_CMD1 | (chn << 8),
|
---|
164 | CTL_CMD2,
|
---|
165 | };
|
---|
166 |
|
---|
167 | if (verbose)
|
---|
168 | printf("AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n",
|
---|
169 | cmd[0], cmd[1], cmd[2]);
|
---|
170 | avc1394_transaction_block(handle, device, cmd, 3, 1);
|
---|
171 |
|
---|
172 | quadlet_t cmd2[3] =
|
---|
173 | {
|
---|
174 | CTL_CMD0 | AVC1394_SA3250_OPERAND_KEY_RELEASE,
|
---|
175 | CTL_CMD1 | (chn << 8),
|
---|
176 | CTL_CMD2,
|
---|
177 | };
|
---|
178 |
|
---|
179 | if (verbose)
|
---|
180 | printf("AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n",
|
---|
181 | cmd2[0], cmd2[1], cmd2[2]);
|
---|
182 | avc1394_transaction_block(handle, device, cmd2, 3, 1);
|
---|
183 |
|
---|
184 | raw1394_destroy_handle(handle);
|
---|
185 |
|
---|
186 | exit(0);
|
---|
187 | }
|
---|
188 |
|
---|