MythTV  master
linuxavcinfo.cpp
Go to the documentation of this file.
1 #include "linuxavcinfo.h"
2 
3 // MythTV headers
4 #include "mythcontext.h"
5 
6 #define LOC QString("LAVCInfo(): ")
7 
8 bool LinuxAVCInfo::Update(uint64_t _guid, raw1394handle_t handle,
9  uint _port, uint _node)
10 {
11  m_port = _port;
12  m_node = _node;
13 
14  if (m_guid == _guid)
15  return true; // we're done
16 
18  // get basic info
19 
20  rom1394_directory dir;
21  if (rom1394_get_directory(handle, _node, &dir) < 0)
22  return false;
23 
24  m_guid = _guid;
25  m_vendorid = dir.vendor_id;
26  m_modelid = dir.model_id;
27  m_specid = dir.unit_spec_id;
28  m_firmware_revision = dir.unit_sw_version;
29  m_product_name = QString("%1").arg(dir.label);
30 
31  if (avc1394_subunit_info(handle, m_node, (uint32_t*)m_unit_table) < 0)
32  memset(m_unit_table, 0xff, sizeof(m_unit_table));
33 
34  return true;
35 }
36 
38 {
39  LOG(VB_RECORD, LOG_INFO,
40  LOC + QString("Getting raw1394 handle for port %1").arg(m_port));
41  m_fwHandle = raw1394_new_handle_on_port(m_port);
42 
43  if (!m_fwHandle)
44  {
45  LOG(VB_GENERAL, LOG_ERR, LOC + "Unable to get handle for " +
46  QString("port: %1").arg(m_port) + ENO);
47 
48  return false;
49  }
50 
51  return true;
52 }
53 
55 {
56  if (m_fwHandle)
57  {
58  LOG(VB_RECORD, LOG_INFO, LOC + "Releasing raw1394 handle");
59  raw1394_destroy_handle(m_fwHandle);
60  m_fwHandle = nullptr;
61  }
62 
63  return true;
64 }
65 
67  const vector<uint8_t> &_cmd,
68  vector<uint8_t> &result,
69  int retry_cnt)
70 {
71  retry_cnt = (retry_cnt < 0) ? 2 : retry_cnt;
72 
73  result.clear();
74 
75  if (!m_fwHandle || (m_node < 0))
76  return false;
77 
78  vector<uint8_t> cmd = _cmd;
79  while (cmd.size() & 0x3)
80  cmd.push_back(0x00);
81 
82  if (cmd.size() > 4096)
83  return false;
84 
85  uint32_t cmdbuf[1024];
86  for (size_t i = 0; i < cmd.size(); i+=4)
87  cmdbuf[i>>2] = cmd[i]<<24 | cmd[i+1]<<16 | cmd[i+2]<<8 | cmd[i+3];
88 
89  uint result_length = 0;
90 
91  uint32_t *ret = avc1394_transaction_block2(
92  m_fwHandle, m_node, cmdbuf, cmd.size() >> 2,
93  &result_length, retry_cnt);
94 
95  if (!ret)
96  return false;
97 
98  for (uint i = 0; i < result_length; i++)
99  {
100  result.push_back((ret[i]>>24) & 0xff);
101  result.push_back((ret[i]>>16) & 0xff);
102  result.push_back((ret[i]>>8) & 0xff);
103  result.push_back((ret[i]) & 0xff);
104  }
105 
106  avc1394_transaction_block_close(m_fwHandle);
107 
108  return true;
109 }
int m_port
Definition: avcinfo.h:38
bool ClosePort(void)
bool SendAVCCommand(const vector< uint8_t > &cmd, vector< uint8_t > &result, int retry_cnt) override
uint m_specid
Definition: avcinfo.h:41
bool Update(uint64_t _guid, raw1394handle_t handle, uint _port, uint _node)
Definition: linuxavcinfo.cpp:8
QString m_product_name
Definition: avcinfo.h:45
uint8_t m_unit_table[32]
Definition: avcinfo.h:46
uint m_firmware_revision
Definition: avcinfo.h:44
uint m_vendorid
Definition: avcinfo.h:42
raw1394handle_t m_fwHandle
Definition: linuxavcinfo.h:45
bool OpenPort(void)
unsigned int uint
Definition: compat.h:140
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:99
int m_node
Definition: avcinfo.h:39
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
#define LOC
Definition: linuxavcinfo.cpp:6
uint m_modelid
Definition: avcinfo.h:43
uint64_t m_guid
Definition: avcinfo.h:40