1 | /* |
---|
2 | * sa4200ch - an external channel changer for SA4200HD Tuner |
---|
3 | * Based off sa3250ch.c by Matt Porter |
---|
4 | * which is |
---|
5 | * Based off 6200ch.c by Stacey D. Son |
---|
6 | * |
---|
7 | * Copyright 2004,2005 by Stacey D. Son <mythdev@son.org> |
---|
8 | * Copyright 2005 Matt Porter <mporter@kernel.crashing.org> |
---|
9 | * Copyright 2006 Oguzhan Eris <eris3@ekls.com> |
---|
10 | * |
---|
11 | * This program is free software; you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; either version 2 of the License, or |
---|
14 | * (at your option) any later version. |
---|
15 | * |
---|
16 | * This program is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU General Public License |
---|
22 | * along with this program; if not, write to the Free Software Foundation, |
---|
23 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
24 | */ |
---|
25 | |
---|
26 | #include <libavc1394/rom1394.h> |
---|
27 | #include <libavc1394/avc1394.h> |
---|
28 | #include <libraw1394/raw1394.h> |
---|
29 | #include <sys/types.h> |
---|
30 | #include <stdio.h> |
---|
31 | #include <errno.h> |
---|
32 | #include <stdlib.h> |
---|
33 | |
---|
34 | /* SA4200HD IDs */ |
---|
35 | #define SA4200HD_VENDOR_ID 0x000014f8 |
---|
36 | #define SA4200HD_MODEL_ID 0x00001072 |
---|
37 | |
---|
38 | #define AVC1394_SA4200_COMMAND_CHANNEL 0x000007c00 /* subunit command */ |
---|
39 | #define AVC1394_SA4200_OPERAND_KEY_PRESS 0xe7 |
---|
40 | #define AVC1394_SA4200_OPERAND_KEY_RELEASE 0x67 |
---|
41 | |
---|
42 | #define CTL_CMD0 AVC1394_CTYPE_CONTROL | AVC1394_SUBUNIT_TYPE_PANEL | \ |
---|
43 | AVC1394_SUBUNIT_ID_0 | AVC1394_SA4200_COMMAND_CHANNEL |
---|
44 | #define CTL_CMD1 (0x04 << 24) |
---|
45 | #define CTL_CMD2 0xff000000 |
---|
46 | |
---|
47 | #define STARTING_NODE 0 |
---|
48 | |
---|
49 | void usage() |
---|
50 | { |
---|
51 | fprintf(stderr, "Usage: sa4200ch [-v] <channel_num>\n"); |
---|
52 | exit(1); |
---|
53 | } |
---|
54 | |
---|
55 | int main (int argc, char *argv[]) |
---|
56 | { |
---|
57 | rom1394_directory dir; |
---|
58 | int device = -1; |
---|
59 | int i; |
---|
60 | int verbose = 0; |
---|
61 | quadlet_t cmd[4]; |
---|
62 | int dig[3]; |
---|
63 | int chn = 708; |
---|
64 | |
---|
65 | if (argc < 2) |
---|
66 | usage(); |
---|
67 | |
---|
68 | if (argc == 3 && argv[1][0] == '-' && argv[1][1] == 'v') { |
---|
69 | verbose = 1; |
---|
70 | chn = atoi(argv[2]); |
---|
71 | } else { |
---|
72 | chn = atoi(argv[1]); |
---|
73 | } |
---|
74 | |
---|
75 | #ifdef RAW1394_V_0_8 |
---|
76 | raw1394handle_t handle = raw1394_get_handle(); |
---|
77 | #else |
---|
78 | raw1394handle_t handle = raw1394_new_handle(); |
---|
79 | #endif |
---|
80 | |
---|
81 | if (!handle) { |
---|
82 | if (!errno) { |
---|
83 | fprintf(stderr, "Not Compatible!\n"); |
---|
84 | } else { |
---|
85 | perror("Couldn't get 1394 handle"); |
---|
86 | fprintf(stderr, "Is ieee1394, driver, and raw1394 loaded?\n"); |
---|
87 | } |
---|
88 | exit(1); |
---|
89 | } |
---|
90 | |
---|
91 | if (raw1394_set_port(handle, 0) < 0) { |
---|
92 | perror("couldn't set port"); |
---|
93 | raw1394_destroy_handle(handle); |
---|
94 | exit(1); |
---|
95 | } |
---|
96 | |
---|
97 | int nc = raw1394_get_nodecount(handle); |
---|
98 | for (i=STARTING_NODE; i < nc; ++i) { |
---|
99 | if (rom1394_get_directory(handle, i, &dir) < 0) { |
---|
100 | fprintf(stderr,"error reading config rom directory for node %d\n", i); |
---|
101 | raw1394_destroy_handle(handle); |
---|
102 | exit(1); |
---|
103 | } |
---|
104 | |
---|
105 | if (verbose) |
---|
106 | printf("node %d: vendor_id = 0x%08x model_id = 0x%08x\n", |
---|
107 | i, dir.vendor_id, dir.model_id); |
---|
108 | |
---|
109 | if ((dir.vendor_id == SA4200HD_VENDOR_ID) && |
---|
110 | (dir.model_id == SA4200HD_MODEL_ID)) { |
---|
111 | device = i; |
---|
112 | break; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | if (device == -1) { |
---|
117 | fprintf(stderr, "Could not find SA4200HD on the 1394 bus.\n"); |
---|
118 | raw1394_destroy_handle(handle); |
---|
119 | exit(1); |
---|
120 | } |
---|
121 | cmd[0] = CTL_CMD0 | AVC1394_SA4200_OPERAND_KEY_PRESS; |
---|
122 | cmd[1] = CTL_CMD1 | (chn << 8); |
---|
123 | cmd[2] = CTL_CMD2; |
---|
124 | cmd[3] = CTL_CMD0 | AVC1394_SA4200_OPERAND_KEY_RELEASE; |
---|
125 | if (verbose) |
---|
126 | printf("AV/C Command: %d%d%d = cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x cmd3=0x%08x\n", |
---|
127 | dig[0] & 0xf, dig[1] & 0xf, dig[2] & 0xf, cmd[0], cmd[1], cmd[2], cmd[3]); |
---|
128 | |
---|
129 | avc1394_transaction_block(handle, 0, cmd, 3, 1); |
---|
130 | raw1394_destroy_handle(handle); |
---|
131 | |
---|
132 | exit(0); |
---|
133 | } |
---|