MythTV  master
linuxavcinfo.cpp
Go to the documentation of this file.
1 #include "linuxavcinfo.h"
2 
3 // MythTV headers
4 #include "libmyth/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.data()) < 0)
32  m_unit_table.fill(0xff);
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 std::vector<uint8_t> &_cmd,
68  std::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  std::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  std::array<uint32_t,1024> cmdbuf {};
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.data(), 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 }
ENO
#define ENO
This can be appended to the LOG args with "+".
Definition: mythlogging.h:74
LinuxAVCInfo::OpenPort
bool OpenPort(void)
Definition: linuxavcinfo.cpp:37
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
LinuxAVCInfo::m_fwHandle
raw1394handle_t m_fwHandle
Definition: linuxavcinfo.h:44
AVCInfo::m_unit_table
std::array< uint8_t, 32 > m_unit_table
Definition: avcinfo.h:53
AVCInfo::m_specid
uint m_specid
Definition: avcinfo.h:48
AVCInfo::m_vendorid
uint m_vendorid
Definition: avcinfo.h:49
AVCInfo::m_product_name
QString m_product_name
Definition: avcinfo.h:52
AVCInfo::m_node
int m_node
Definition: avcinfo.h:46
AVCInfo::m_firmware_revision
uint m_firmware_revision
Definition: avcinfo.h:51
AVCInfo::m_modelid
uint m_modelid
Definition: avcinfo.h:50
LinuxAVCInfo::Update
bool Update(uint64_t _guid, raw1394handle_t handle, uint _port, uint _node)
Definition: linuxavcinfo.cpp:8
mythcontext.h
AVCInfo::m_guid
uint64_t m_guid
Definition: avcinfo.h:47
AVCInfo::m_port
int m_port
Definition: avcinfo.h:45
LinuxAVCInfo::SendAVCCommand
bool SendAVCCommand(const std::vector< uint8_t > &cmd, std::vector< uint8_t > &result, int retry_cnt) override
Definition: linuxavcinfo.cpp:66
LOC
#define LOC
Definition: linuxavcinfo.cpp:6
LinuxAVCInfo::ClosePort
bool ClosePort(void)
Definition: linuxavcinfo.cpp:54
uint
unsigned int uint
Definition: freesurround.h:24
linuxavcinfo.h