10 #include <netinet/in.h>
13 #include <vdr/plugin.h>
14 #include <vdr/remote.h>
15 #include <vdr/status.h>
16 #include <vdr/thread.h>
17 #include <vdr/tools.h>
22 #define REPEATLIMIT 150 // ms
23 #define REPEATDELAY 350 // ms
24 #define HANDSHAKETIMEOUT 20 // ms
25 #define DEFAULTDEVICE "/dev/ttyS1"
40 void SetCode(
unsigned char Code);
41 void SetMode(
unsigned char Mode);
43 void SetPoints(
unsigned char Dp,
bool On);
52 virtual bool Ready(
void);
66 if ((
f = open(DeviceName, O_RDWR | O_NONBLOCK)) >= 0) {
68 if (tcgetattr(
f, &t) == 0) {
69 cfsetspeed(&t, B9600);
71 if (tcsetattr(
f, TCSAFLUSH, &t) == 0) {
104 unsigned char Code =
'0';
105 isyslog(
"trying codes for %s remote control...",
Name());
112 isyslog(
"established connection to %s remote control using code %c",
Name(),
code);
114 snprintf(buffer,
sizeof(buffer),
"%c",
code);
126 unsigned short address;
127 unsigned int command;
129 unsigned char raw[6];
133 time_t LastCodeRefresh = 0;
135 unsigned char LastCode = 0, LastMode = 0;
136 uint64_t LastCommand = ~0;
137 unsigned int LastData = 0;
142 for (
int i = 0; i < 6; i++) {
147 unsigned short Address = ntohs(buffer.data.address);
148 uint64_t Command = ntohl(buffer.data.command);
149 if (
code ==
'B' && Address == 0x0000 && Command == 0x00004000)
154 Command |= uint64_t(Address) << 32;
155 if (Command != LastCommand) {
156 LastCommand = Command;
165 Put(Command, repeat);
174 Put(LastCommand,
false,
true);
179 unsigned int d =
data;
184 unsigned char c =
code;
189 unsigned char m =
mode;
196 if (!repeat &&
code && time(NULL) - LastCodeRefresh > 60) {
198 LastCodeRefresh = time(NULL);
219 int w = write(
f, &c, 1);
224 else if (reply ==
'X') {
226 for (
int i = 6; i--;) {
242 for (
int retry = 5; retry--;) {
251 for (
int i = 0; i < 4; i++) {
279 sprintf(buf,
"%4d", n & 0xFFFF);
281 for (
char *d = buf; *d; d++) {
284 n = (n << 4) | ((*d -
'0') & 0x0F);
288 for (
int i = 0; i < 4; i++) {
290 m |= ((i & 0x03) << 5) | (n & 0x0F) | (((
dp >> i) & 0x01) << 4);
298 const char *chars =
mode ==
modeH ?
"0123456789ABCDEF" :
"0123456789-EHLP ";
301 for (
int i = 0; *s && i < 4; s++, i++) {
303 for (
const char *c = chars; *c; c++) {
331 if (*Code < 'A' || *Code >
'D') {
338 sprintf(buf,
"C0D%c", *Code);
358 if (ChannelNumber && LiveView)
377 virtual bool Start(
void);
391 return " -d DEV, --device=DEV set the device to use (default is " DEFAULTDEVICE ")\n";
397 static struct option long_options[] = {
398 {
"dev", required_argument, NULL,
'd' },
399 { NULL, no_argument, NULL, 0 }
403 while ((c = getopt_long(argc, argv,
"d:", long_options, NULL)) != -1) {
405 case 'd':
device = optarg;
407 default:
return false;