MythTV master
firewiredevice.cpp
Go to the documentation of this file.
1
7// C++ headers
8#include <algorithm>
9#include <chrono> // for milliseconds
10#include <thread> // for sleep_for
11
12// Qt headers
13#include <QMap>
14
15// MythTV headers
16#include "libmythbase/mythconfig.h"
18
19#include "linuxfirewiredevice.h"
20#if CONFIG_FIREWIRE_OSX
22#endif
23#include "mpeg/mpegtables.h"
24
25#define LOC QString("FireDev(%1): ").arg(guid_to_string(m_guid))
26
27static void fw_init(QMap<uint64_t,QString> &id_to_model);
28
29QMap<uint64_t,QString> FirewireDevice::s_idToModel;
31
32FirewireDevice::FirewireDevice(uint64_t guid, uint subunitid, uint speed) :
33 m_guid(guid), m_subunitid(subunitid),
34 m_speed(speed)
35{
36}
37
39{
40 if (listener)
41 {
42 auto it = find(m_listeners.begin(), m_listeners.end(), listener);
43 if (it == m_listeners.end())
44 m_listeners.push_back(listener);
45 }
46
47 LOG(VB_RECORD, LOG_INFO, LOC +
48 QString("AddListener() %1").arg(m_listeners.size()));
49}
50
52{
53 auto it = m_listeners.end();
54
55 do
56 {
57 it = find(m_listeners.begin(), m_listeners.end(), listener);
58 if (it != m_listeners.end())
59 it = m_listeners.erase(it);
60 }
61 while (it != m_listeners.end());
62
63 LOG(VB_RECORD, LOG_INFO, LOC +
64 QString("RemoveListener() %1").arg(m_listeners.size()));
65}
66
68{
69 QMutexLocker locker(&m_lock);
70
71 std::vector<uint8_t> cmd;
72 std::vector<uint8_t> ret;
73
74 cmd.push_back(kAVCControlCommand);
76 cmd.push_back(kAVCUnitPowerOpcode);
77 cmd.push_back((on) ? kAVCPowerStateOn : kAVCPowerStateOff);
78
79 QString cmdStr = (on) ? "on" : "off";
80 LOG(VB_RECORD, LOG_INFO, LOC + QString("Powering %1").arg(cmdStr));
81
82 if (!SendAVCCommand(cmd, ret, -1))
83 {
84 LOG(VB_GENERAL, LOG_ERR, LOC + "Power on cmd failed (no response)");
85 return false;
86 }
87
88 if (kAVCAcceptedStatus != ret[0])
89 {
90 LOG(VB_GENERAL, LOG_ERR, LOC + QString("Power %1 failed").arg(cmdStr));
91
92 return false;
93 }
94
95 LOG(VB_RECORD, LOG_INFO, LOC +
96 QString("Power %1 cmd sent successfully").arg(cmdStr));
97
98 return true;
99}
100
102{
103 QMutexLocker locker(&m_lock);
104
105 std::vector<uint8_t> cmd;
106 std::vector<uint8_t> ret;
107
108 cmd.push_back(kAVCStatusInquiryCommand);
110 cmd.push_back(kAVCUnitPowerOpcode);
111 cmd.push_back(kAVCPowerStateQuery);
112
113 LOG(VB_CHANNEL, LOG_INFO, LOC + "Requesting STB Power State");
114
115 if (!SendAVCCommand(cmd, ret, -1))
116 {
117 LOG(VB_GENERAL, LOG_ERR, LOC + "Power cmd failed (no response)");
119 }
120
121 QString loc = LOC + "STB Power State: ";
122
123 if (ret[0] != kAVCResponseImplemented)
124 {
125 LOG(VB_CHANNEL, LOG_INFO, loc + "Query not implemented");
126 return kAVCPowerUnknown;
127 }
128
129 // check 1st operand..
130 if (ret[3] == kAVCPowerStateOn)
131 {
132 LOG(VB_CHANNEL, LOG_INFO, loc + "On");
133 return kAVCPowerOn;
134 }
135
136 if (ret[3] == kAVCPowerStateOff)
137 {
138 LOG(VB_CHANNEL, LOG_INFO, loc + "Off");
139 return kAVCPowerOff;
140 }
141
142 LOG(VB_GENERAL, LOG_ERR, LOC + "STB Power State: Unknown Response");
143
144 return kAVCPowerUnknown;
145}
146
147bool FirewireDevice::SetChannel(const QString &panel_model,
148 uint alt_method, uint channel)
149{
150 LOG(VB_CHANNEL, LOG_INFO, QString("SetChannel(model %1, alt %2, chan %3)")
151 .arg(panel_model).arg(alt_method).arg(channel));
152
153 QMutexLocker locker(&m_lock);
154 LOG(VB_CHANNEL, LOG_INFO, "SetChannel() -- locked");
155
156 if (!IsSTBSupported(panel_model))
157 {
158 LOG(VB_GENERAL, LOG_ERR, LOC +
159 QString("Model: '%1' ").arg(panel_model) +
160 "is not supported by internal channel changer.");
161 return false;
162 }
163
164 std::array<uint,3> digit {
165 (channel % 1000) / 100,
166 (channel % 100) / 10,
167 (channel % 10)
168 };
169
171 {
172 LOG(VB_GENERAL, LOG_ERR, LOC +
173 "SetChannel: Extended subunits are not supported.");
174
175 return false;
176 }
177
178 std::vector<uint8_t> cmd;
179 std::vector<uint8_t> ret;
180
181 if ((panel_model.toUpper() == "SA GENERIC") ||
182 (panel_model.toUpper() == "SA4200HD") ||
183 (panel_model.toUpper() == "SA4250HDC"))
184 {
185 if (panel_model.toUpper() == "SA4250HDC")
186 {
187 LOG(VB_GENERAL, LOG_ERR, LOC +
188 "The Scientific Atlanta 4250 HDC is not supported "
189 "\n\t\t\tby any MythTV Firewire channel changer."
190 "At the moment you must use an IR blaster.");
191 }
192
193 cmd.push_back(kAVCControlCommand);
194 cmd.push_back(kAVCSubunitTypePanel | m_subunitid);
195 cmd.push_back(kAVCPanelPassThrough);
197
198 cmd.push_back(4); // operand length
199 cmd.push_back((channel>>8) & 0x0f);
200 cmd.push_back(channel & 0xff);
201 cmd.push_back(0x00);
202 cmd.push_back(0x00);
203
204 if (!SendAVCCommand(cmd, ret, -1))
205 return false;
206
207 bool press_ok = (kAVCAcceptedStatus == ret[0]);
208
210 if (!SendAVCCommand(cmd, ret, -1))
211 return false;
212
213 bool release_ok = (kAVCAcceptedStatus == ret[0]);
214
215 if (!press_ok && !release_ok)
216 {
217 LOG(VB_GENERAL, LOG_ERR, LOC + "Tuning failed");
218 return false;
219 }
220
221 SetLastChannel(channel);
222 return true;
223 }
224
225 // the PACE is obviously not a Motorola channel changer, but the
226 // same commands work for it as the Motorola.
227 bool is_mot = ((panel_model.startsWith("DCT-", Qt::CaseInsensitive)) ||
228 (panel_model.startsWith("DCH-", Qt::CaseInsensitive)) ||
229 (panel_model.startsWith("DCX-", Qt::CaseInsensitive)) ||
230 (panel_model.startsWith("QIP-", Qt::CaseInsensitive)) ||
231 (panel_model.startsWith("MOTO", Qt::CaseInsensitive)) ||
232 (panel_model.startsWith("PACE-", Qt::CaseInsensitive)));
233
234 if (is_mot && !alt_method)
235 {
236 for (uint d : digit)
237 {
238 cmd.clear();
239 cmd.push_back(kAVCControlCommand);
240 cmd.push_back(kAVCSubunitTypePanel | m_subunitid);
241 cmd.push_back(kAVCPanelPassThrough);
242 cmd.push_back((kAVCPanelKey0 + d) | kAVCPanelKeyPress);
243 cmd.push_back(0x00);
244 cmd.push_back(0x00);
245 cmd.push_back(0x00);
246 cmd.push_back(0x00);
247
248 if (!SendAVCCommand(cmd, ret, -1))
249 return false;
250
251 std::this_thread::sleep_for(500ms);
252 }
253
254 SetLastChannel(channel);
255 return true;
256 }
257
258 if (is_mot && alt_method)
259 {
260 cmd.push_back(kAVCControlCommand);
261 cmd.push_back(kAVCSubunitTypePanel | m_subunitid);
262 cmd.push_back(kAVCPanelPassThrough);
264
265 cmd.push_back(4); // operand length
266 cmd.push_back((channel>>8) & 0x0f);
267 cmd.push_back(channel & 0xff);
268 cmd.push_back(0x00);
269 cmd.push_back(0xff);
270
271 if (!SendAVCCommand(cmd, ret, -1))
272 return false;
273
274 SetLastChannel(channel);
275 return true;
276 }
277
278 if (panel_model.toUpper() == "SA3250HD")
279 {
280 cmd.push_back(kAVCControlCommand);
281 cmd.push_back(kAVCSubunitTypePanel | m_subunitid);
282 cmd.push_back(kAVCPanelPassThrough);
284
285 cmd.push_back(4); // operand length
286 cmd.push_back(0x30 | digit[2]);
287 cmd.push_back(0x30 | digit[1]);
288 cmd.push_back(0x30 | digit[0]);
289 cmd.push_back(0xff);
290
291 if (!SendAVCCommand(cmd, ret, -1))
292 return false;
293
294 cmd[5] = 0x30 | digit[0];
295 cmd[6] = 0x30 | digit[1];
296 cmd[7] = 0x30 | digit[2];
297
298 if (!SendAVCCommand(cmd, ret, -1))
299 return false;
300
301 SetLastChannel(channel);
302 return true;
303 }
304
305 return false;
306}
307
309 const unsigned char *data, uint dataSize)
310{
311 if ((dataSize >= TSPacket::kSize) && (data[0] == SYNC_BYTE) &&
312 ((data[1] & 0x1f) == 0) && (data[2] == 0))
313 {
314 ProcessPATPacket(*(reinterpret_cast<const TSPacket*>(data)));
315 }
316
317 for (auto & listener : m_listeners)
318 listener->AddData(data, dataSize);
319}
320
322{
323 m_bufferCleared = (channel == m_lastChannel);
324 m_lastChannel = channel;
325
326 LOG(VB_GENERAL, LOG_INFO, QString("SetLastChannel(%1): cleared: %2")
327 .arg(channel).arg(m_bufferCleared ? "yes" : "no"));
328}
329
331{
332 if (!tspacket.TransportError() && !tspacket.Scrambled() &&
333 tspacket.HasPayload() && tspacket.PayloadStart() && (tspacket.PID() == 0))
334 {
335 PSIPTable pes(tspacket);
336 uint crc = pes.CalcCRC();
337 m_bufferCleared |= (crc != m_lastCrc);
338 m_lastCrc = crc;
339#if 0
340 LOG(VB_RECORD, LOG_DEBUG, LOC +
341 QString("ProcessPATPacket: CRC 0x%1 cleared: %2")
342 .arg(crc,0,16).arg(m_bufferCleared ? "yes" : "no"));
343#endif
344 }
345 else
346 {
347 LOG(VB_GENERAL, LOG_ERR, LOC + "Can't handle large PAT's");
348 }
349}
350
351QString FirewireDevice::GetModelName(uint vendor_id, uint model_id)
352{
353 QMutexLocker locker(&s_staticLock);
354 if (s_idToModel.empty())
356
357 QString ret = s_idToModel[(((uint64_t) vendor_id) << 32) | model_id];
358
359 if (ret.isEmpty())
360 return "MOTO GENERIC";
361 return ret;
362}
363
364std::vector<AVCInfo> FirewireDevice::GetSTBList(void)
365{
366 std::vector<AVCInfo> list;
367
368#if CONFIG_FIREWIRE_LINUX
370#elif CONFIG_FIREWIRE_OSX
372#endif
373
374// #define DEBUG_AVC_INFO
375#ifdef DEBUG_AVC_INFO
377 info.m_guid = 0x0016928a7b600001ULL;
378 info.m_specid = 0x0;
379 info.m_vendorid = 0x000014f8;
380 info.m_modelid = 0x00001072;
381 info.m_firmware_revision = 0x0;
382 info.m_product_name = "Explorer 4200 HD";
383 list.push_back(info);
384
385 info.m_guid = 0xff2145a850e39810ULL;
386 info.m_specid = 0x0;
387 info.m_vendorid = 0x000014f8;
388 info.m_modelid = 0x00000be0;
389 info.m_firmware_revision = 0x0;
390 info.m_product_name = "Explorer 3250 HD";
391 list.push_back(info);
392#endif // DEBUG_AVC_INFO
393
394 return list;
395}
396
397static void fw_init(QMap<uint64_t,QString> &id_to_model)
398{
399 const std::array<const uint64_t,16> sa_vendor_ids
400 {
401 0x0a73, 0x0f21, 0x11e6, 0x14f8, 0x1692, 0x1868,
402 0x1947, 0x1ac3, 0x1bd7, 0x1cea, 0x1e6b, 0x21be,
403 0x223a, 0x22ce, 0x23be, 0x252e,
404 };
405
406 for (uint64_t vendor_id : sa_vendor_ids)
407 {
408 id_to_model[vendor_id << 32 | 0x0be0] = "SA3250HD";
409 id_to_model[vendor_id << 32 | 0x1072] = "SA4200HD";
410 id_to_model[vendor_id << 32 | 0x10cc] = "SA4250HDC";
411 id_to_model[vendor_id << 32 | 0x22ce] = "SA8300HD";
412 }
413
414 const std::array<uint64_t,59> motorola_vendor_ids
415 {
416 /* DCH-3200, DCX-3200 */
417 0x1c11, 0x1cfb, 0x1fc4, 0x23a3, 0x23ee, 0x25f1,
418 0xfa01, 0x25f1, 0x25f2, 0xcc7d37, 0x946269, 0x6455b1,
419 /* DCX-3432 */
420 0x24a0,
421 /* DCH-3416 */
422 0x1e46,
423 /* DCT-3416 */
424 0x1bdd,
425 /* DCT-3412 */
426 0x159a,
427 /* DCT-6200, DCT-3416 */
428 0x0ce5, 0x0e5c, 0x1225, 0x0f9f, 0x1180,
429 0x12c9, 0x11ae, 0x152f, 0x14e8, 0x16b5, 0x1371,
430 0x19a6, 0x1aad, 0x0b06, 0x195e, 0x10dc,
431 /* DCT-6212 */
432 0x0f9f, 0x152f,
433 /* DCT-6216, 2224 */
434 0x17ee, 0x1a66,
435 /* QIP 6200 */
436 0x211e,
437 /* QIP 7100 */
438 0x2374,
439 /* unknown, see http://standards.ieee.org/regauth/oui/oui.txt */
440 0x04db, 0x0406, 0x0ce5, 0x111a, 0x1225, 0x1404,
441 0x1626, 0x18c0, 0x1ade, 0x1cfb, 0x2040, 0x2180,
442 0x2210, 0x230b, 0x2375, 0x2395, 0x23a2, 0x23ed,
443 0x23ee, 0x23a0, 0x23a1,
444 };
445
446 for (uint64_t vendor_id : motorola_vendor_ids)
447 {
448 id_to_model[vendor_id << 32 | 0xf740] = "DCX-3200";
449 id_to_model[vendor_id << 32 | 0xf804] = "DCX-3200";
450 id_to_model[vendor_id << 32 | 0xfa03] = "DCX-3200";
451 id_to_model[vendor_id << 32 | 0xfa05] = "DCX-3200";
452 id_to_model[vendor_id << 32 | 0xfa07] = "DCX-3200";
453 id_to_model[vendor_id << 32 | 0x24a1] = "DCX-3200";
454 id_to_model[vendor_id << 32 | 0x2322] = "DCX-3200";
455 id_to_model[vendor_id << 32 | 0xea05] = "DCX-3432";
456 id_to_model[vendor_id << 32 | 0xd330] = "DCH-3200";
457 id_to_model[vendor_id << 32 | 0xb630] = "DCH-3416";
458 id_to_model[vendor_id << 32 | 0x34cb] = "DCT-3412";
459 id_to_model[vendor_id << 32 | 0x346b] = "DCT-3416";
460 id_to_model[vendor_id << 32 | 0xb630] = "DCT-3416";
461 id_to_model[vendor_id << 32 | 0x6200] = "DCT-6200";
462 id_to_model[vendor_id << 32 | 0x620a] = "DCT-6200";
463 id_to_model[vendor_id << 32 | 0x64ca] = "DCT-6212";
464 id_to_model[vendor_id << 32 | 0x64cb] = "DCT-6212";
465 id_to_model[vendor_id << 32 | 0x646b] = "DCT-6216";
466 id_to_model[vendor_id << 32 | 0x8100] = "QIP-7100";
467 id_to_model[vendor_id << 32 | 0x7100] = "QIP-6200";
468 id_to_model[vendor_id << 32 | 0x0001] = "QIP-7100";
469 }
470
471 const std::array<const uint64_t,2> pace_vendor_ids
472 {
473 /* PACE 550-HD & 779 */
474 0x1cc3, 0x5094,
475 };
476
477 for (uint64_t vendor_id : pace_vendor_ids)
478 {
479 id_to_model[vendor_id << 32 | 0x10551] = "PACE-550";
480 id_to_model[vendor_id << 32 | 0x10755] = "PACE-779";
481 }
482}
483
484bool FirewireDevice::IsSTBSupported(const QString &panel_model)
485{
486 QString model = panel_model.toUpper();
487 return ((model == "DCH-3200") ||
488 (model == "DCH-3416") ||
489 (model == "DCT-3412") ||
490 (model == "DCT-3416") ||
491 (model == "DCT-6200") ||
492 (model == "DCT-6212") ||
493 (model == "DCT-6216") ||
494 (model == "DCX-3200") ||
495 (model == "SA3250HD") ||
496 (model == "SA4200HD") ||
497 (model == "SA4250HDC") ||
498 (model == "SA8300HD") ||
499 (model == "PACE-550") ||
500 (model == "PACE-779") ||
501 (model == "QIP-6200") ||
502 (model == "QIP-7100") ||
503 (model == "SA GENERIC") ||
504 (model == "MOTO GENERIC"));
505}
static std::vector< AVCInfo > GetSTBList(void)
virtual void AddListener(TSDataListener *listener)
void ProcessPATPacket(const TSPacket &tspacket)
static QMap< uint64_t, QString > s_idToModel
Vendor ID + Model ID to FirewireDevice STB model string.
virtual void RemoveListener(TSDataListener *listener)
void SetLastChannel(uint channel)
static QMutex s_staticLock
FirewireDevice(uint64_t guid, uint subunitid, uint speed)
virtual PowerState GetPowerState(void)
static std::vector< AVCInfo > GetSTBList(void)
std::vector< TSDataListener * > m_listeners
virtual bool SendAVCCommand(const std::vector< uint8_t > &cmd, std::vector< uint8_t > &result, int retry_cnt)=0
virtual bool SetChannel(const QString &panel_model, uint alt_method, uint channel)
static bool IsSTBSupported(const QString &model)
static QString GetModelName(uint vendor_id, uint model_id)
virtual bool SetPowerState(bool on)
virtual void BroadcastToListeners(const unsigned char *data, uint dataSize)
static std::vector< AVCInfo > GetSTBList(void)
uint CalcCRC(void) const
Definition: pespacket.cpp:172
A PSIP table is a variant of a PES packet containing an MPEG, ATSC or DVB table.
Definition: mpegtables.h:410
unsigned int PID(void) const
Definition: tspacket.h:93
bool HasPayload(void) const
Definition: tspacket.h:116
bool PayloadStart(void) const
Definition: tspacket.h:89
bool TransportError(void) const
Definition: tspacket.h:86
bool Scrambled(void) const
Definition: tspacket.h:112
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:208
static constexpr unsigned int kSize
Definition: tspacket.h:261
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
#define LOC
FirewireDevice Copyright (c) 2005 by Jim Westfall Distributed as part of MythTV under GPL v2 and late...
static void fw_init(QMap< uint64_t, QString > &id_to_model)
unsigned int uint
Definition: freesurround.h:24
static const iso6937table * d
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
dictionary info
Definition: azlyrics.py:7
static constexpr uint8_t SYNC_BYTE
Definition: tspacket.h:21