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>
22#define REPEATLIMIT 150
23#define REPEATDELAY 350
24#define HANDSHAKETIMEOUT 20
25#define DEFAULTDEVICE "/dev/ttyS1"
42 void SetCode(
unsigned char Code);
43 void SetMode(
unsigned char Mode);
45 void SetPoints(
unsigned char Dp,
bool On);
54 virtual bool Ready(
void);
69 if ((
f = open(DeviceName, O_RDWR | O_NONBLOCK)) >= 0) {
71 if (tcgetattr(
f, &t) == 0) {
72 cfsetspeed(&t, B9600);
74 if (tcsetattr(
f, TCSAFLUSH, &t) == 0) {
107 unsigned char Code =
'0';
108 isyslog(
"trying codes for %s remote control...",
Name());
115 isyslog(
"established connection to %s remote control using code %c",
Name(),
code);
117 snprintf(buffer,
sizeof(buffer),
"%c",
code);
129 unsigned short address;
130 unsigned int command;
132 unsigned char raw[6];
136 time_t LastCodeRefresh = 0;
138 unsigned char LastCode = 0, LastMode = 0;
139 uint64_t LastCommand = ~0;
140 unsigned int LastData = 0;
145 for (
int i = 0; i < 6; i++) {
150 unsigned short Address = ntohs(buffer.data.address);
151 uint64_t Command = ntohl(buffer.data.command);
152 if (
code ==
'B' && Address == 0x0000 && Command == 0x00004000)
157 Command |= uint64_t(Address) << 32;
158 if (Command != LastCommand) {
159 LastCommand = Command;
168 Put(Command, repeat);
177 Put(LastCommand,
false,
true);
182 unsigned int d =
data;
187 unsigned char c =
code;
192 unsigned char m =
mode;
199 if (!repeat &&
code && time(NULL) - LastCodeRefresh > 60) {
201 LastCodeRefresh = time(NULL);
222 int w = write(
f, &c, 1);
227 else if (reply ==
'X') {
229 for (
int i = 6; i--;) {
245 for (
int retry = 5; retry--;) {
254 for (
int i = 0; i < 4; i++) {
282 sprintf(buf,
"%4d", n & 0xFFFF);
284 for (
char *d = buf; *d; d++) {
287 n = (n << 4) | ((*d -
'0') & 0x0F);
291 for (
int i = 0; i < 4; i++) {
293 m |= ((i & 0x03) << 5) | (n & 0x0F) | (((
dp >> i) & 0x01) << 4);
301 const char *chars =
mode ==
modeH ?
"0123456789ABCDEF" :
"0123456789-EHLP ";
304 for (
int i = 0; *s && i < 4; s++, i++) {
306 for (
const char *c = chars; *c; c++) {
334 if (*Code <
'A' || *Code >
'D') {
341 sprintf(buf,
"C0D%c", *Code);
361 if (ChannelNumber && LiveView)
384 virtual bool Start(
void);
398 return " -d DEV, --device=DEV set the device to use (default is " DEFAULTDEVICE ")\n";
404 static struct option long_options[] = {
405 {
"dev", required_argument, NULL,
'd' },
406 { NULL, no_argument, NULL, 0 }
410 while ((c = getopt_long(argc, argv,
"d:", long_options, NULL)) != -1) {
412 case 'd':
device = optarg;
414 default:
return false;
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
static bool FileReady(int FileDes, int TimeoutMs=1000)
virtual bool ProcessArgs(int argc, char *argv[])
virtual const char * Description(void)
virtual const char * Version(void)
virtual const char * CommandLineHelp(void)
int ReceiveByte(int TimeoutMs=0)
bool SendCommand(unsigned char Cmd)
bool SendByteHandshake(unsigned char c)
virtual void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On)
bool DetectCode(unsigned char *Code)
unsigned char counter[MAXPOINTS]
void SetNumber(int n, bool Hex=false)
bool SendData(unsigned int n)
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
void SetPoints(unsigned char Dp, bool On)
virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber, bool LiveView)
void SetCode(unsigned char Code)
void SetMode(unsigned char Mode)
bool SendByte(unsigned char c)
cRcuRemote(const char *DeviceName)
virtual bool Initialize(void)
void SetString(const char *s)
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
const char * GetSetup(void)
cRemote(const char *Name)
void PutSetup(const char *Setup)
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
cThread(const char *Description=NULL, bool LowPriority=false)
Creates a new thread.
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
uint64_t Elapsed(void) const
Returns the number of milliseconds that have elapsed since the last call to Set().
void Set(int Ms=0)
Sets the timer.
static const char * VERSION
static const char * DESCRIPTION
#define VDRPLUGINCREATOR(PluginClass)
static const char * VERSION
static const char * DESCRIPTION