Go to the documentation of this file.
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;
140 while (Running() &&
f >= 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;
static const char * DESCRIPTION
VDRPLUGINCREATOR(cPluginRcu)
bool SendCommand(unsigned char Cmd)
virtual const char * Version(void)
void SetPoints(unsigned char Dp, bool On)
static bool FileReady(int FileDes, int TimeoutMs=1000)
virtual const char * CommandLineHelp(void)
virtual const char * Description(void)
bool Receiving(bool Dummy=false) const
Returns true if we are currently receiving. The parameter has no meaning (for backwards compatibility...
virtual void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On)
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
void SetString(const char *s)
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
void PutSetup(const char *Setup)
virtual bool ProcessArgs(int argc, char *argv[])
bool SendByteHandshake(unsigned char c)
bool DetectCode(unsigned char *Code)
cRcuRemote(const char *DeviceName)
const char * GetSetup(void)
void SetCode(unsigned char Code)
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
static const char * VERSION
virtual void ChannelSwitch(const cDevice *Device, int ChannelNumber, bool LiveView)
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
virtual bool Initialize(void)
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
bool SendByte(unsigned char c)
void SetNumber(int n, bool Hex=false)
uint64_t Elapsed(void) const
bool SendData(unsigned int n)
void SetMode(unsigned char Mode)
int ReceiveByte(int TimeoutMs=0)