12 #include <linux/dvb/frontend.h>
13 #include <sys/ioctl.h>
17 #define ALL_DEVICES (~0) // all bits set to '1'
18 #define MAX_DEVICES 32 // each bit in a 32-bit integer represents one device
24 return *s && s[strlen(s) - 1] ==
':';
32 while (*p && *p !=
':') {
34 int d = strtol(p, &t, 10);
39 esyslog(
"ERROR: invalid device number %d in '%s'", d, s);
68 struct dvb_diseqc_master_cmd cmd;
69 NumCodes =
min(NumCodes,
int(
sizeof(cmd.msg) - 2));
71 cmd.msg[cmd.msg_len++] = 0xE0;
72 cmd.msg[cmd.msg_len++] = 0x31;
73 for (
int i = 0; i < NumCodes; i++)
74 cmd.msg[cmd.msg_len++] = Codes[i];
75 CHECK(ioctl(Frontend(), FE_DISEQC_SEND_MASTER_CMD, &cmd));
80 uint8_t Code[] = { uint8_t(Direction ==
pdLeft ? 0x68 : 0x69), 0x00 };
88 uint8_t Code[] = { uint8_t(Direction ==
pdLeft ? 0x68 : 0x69), 0xFF };
89 Code[1] -=
min(Steps, uint(0x7F)) - 1;
95 uint8_t Code[] = { 0x60 };
101 uint8_t Code[] = { uint8_t(Direction ==
pdLeft ? 0x66 : 0x67) };
107 uint8_t Code[] = { 0x63 };
113 uint8_t Code[] = { 0x6A, 0x00 };
119 uint8_t Code[] = { 0x6A, uint8_t(Number) };
125 uint8_t Code[] = { 0x6F, uint8_t(Number), 0x00, 0x00 };
131 uint8_t Code[] = { 0x6B, uint8_t(Number) };
138 uint8_t Code[] = { 0x6E, 0x00, 0x00 };
141 Code[1] = a / 10 / 16;
142 Code[2] = a / 10 % 16 * 16 + a % 10 * 16 / 10;
143 Code[1] |= (Angle < 0) ? 0xE0 : 0xD0;
166 if (fields == 2 || fields == 3) {
169 if (fields == 3 && (pin < 0 || pin > 255)) {
184 bool cScrs::Load(
const char *FileName,
bool AllowComments,
bool MustExist)
193 for (
cScr *p = First(); p; p =
Next(p)) {
194 if (!
IsBitSet(p->Devices(), Device - 1))
230 char *sourcebuf = NULL;
234 if (4 <= fields && fields <= 5) {
240 const char *CurrentAction = NULL;
241 while (
Execute(&CurrentAction, NULL, NULL, NULL, NULL) !=
daNone)
244 result = !
commands || !*CurrentAction;
250 esyslog(
"ERROR: unknown source '%s'", sourcebuf);
258 if ((Codes[0] & 0xF0) == 0x70 ) {
259 int t = SatFrequency == 0 ? 0 : (SatFrequency - 100);
260 if (t < 2048 && Scr->Channel() >= 0 && Scr->
Channel() < 32) {
261 Codes[1] = t >> 8 | Scr->
Channel() << 3;
263 Codes[3] = (t == 0 ? 0 :
scrBank);
269 int t = SatFrequency == 0 ? 0 : (SatFrequency + Scr->
UserBand() + 2) / 4 - 350;
270 if (t < 1024 && Scr->Channel() >= 0 && Scr->
Channel() < 8) {
271 Codes[3] = t >> 8 | (t == 0 ? 0 :
scrBank << 2) | Scr->
Channel() << 5;
274 return (t + 350) * 4 - SatFrequency;
277 esyslog(
"ERROR: invalid SCR channel number %d or frequency %d", Scr->
Channel(),SatFrequency);
283 if ((Codes[0] & 0xF0) == 0x70 ) {
284 if (Scr->
Pin() >= 0 && Scr->
Pin() <= 255) {
286 Codes[4] = Scr->
Pin();
295 if (Scr->
Pin() >= 0 && Scr->
Pin() <= 255) {
297 Codes[5] = Scr->
Pin();
311 int n = strtol(s, &p, 10);
312 if (!errno && p != s && n >= 0) {
317 esyslog(
"ERROR: invalid value for wait time in '%s'", s - 1);
323 if (!*s || !isdigit(*s)) {
329 int n = strtol(s, &p, 10);
330 if (!errno && p != s && n >= 0 && n < 0xFF) {
335 esyslog(
"ERROR: more than one position in '%s'", s - 1);
339 esyslog(
"ERROR: invalid satellite position in '%s'", s - 1);
347 int n = strtol(s, &p, 10);
348 if (!errno && p != s && n >= 0 && n < 256) {
353 esyslog(
"ERROR: more than one scr bank in '%s'", s - 1);
357 esyslog(
"ERROR: invalid value for scr bank in '%s'", s - 1);
363 const char *e = strchr(s,
']');
371 int n = strtol(t, &p, 16);
372 if (!errno && p != t && 0 <= n && n <= 255) {
374 if (NumCodes < *MaxCodes)
375 Codes[NumCodes++] =
uchar(n);
377 esyslog(
"ERROR: too many codes in code sequence '%s'", s - 1);
384 esyslog(
"ERROR: invalid code at '%s'", t);
389 esyslog(
"ERROR: too many codes in code sequence '%s'", s - 1);
394 *MaxCodes = NumCodes;
398 esyslog(
"ERROR: missing closing ']' in code sequence '%s'", s - 1);
406 while (*CurrentAction && **CurrentAction) {
407 switch (*(*CurrentAction)++) {
415 case 'W': *CurrentAction =
Wait(*CurrentAction);
return daWait;
416 case 'P': *CurrentAction =
GetPosition(*CurrentAction);
421 case '[': *CurrentAction =
GetCodes(*CurrentAction, Codes, MaxCodes);
422 if (*CurrentAction) {
423 if (Scr && Frequency) {
430 default:
esyslog(
"ERROR: unknown diseqc code '%c'", *(*CurrentAction - 1));
450 if (!
IsBitSet(p->Devices(), Device - 1))
452 if (
cSource::Matches(p->Source(), Source) && p->Slof() > Frequency && p->Polarization() == toupper(Polarization)) {
453 if (p->IsScr() && Scr && !*Scr) {
456 dsyslog(
"SCR %d assigned to device %d", (*Scr)->Channel(), Device);
458 esyslog(
"ERROR: no free SCR entry available for device %d", Device);