vdr  2.2.0
hdffcmd_generic.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * HDFF firmware command interface library
4  *
5  * Copyright (C) 2011 Andreas Regel
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the
19  * Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *********************************************************************/
23 
24 #include <errno.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <sys/ioctl.h>
28 
29 #include "hdffcmd.h"
30 #include "hdffcmd_base.h"
31 #include "hdffcmd_defs.h"
32 
33 int HdffCmdGetFirmwareVersion(int OsdDevice, uint32_t * Version, char * String,
34  uint32_t MaxLength)
35 {
36  uint8_t cmdData[8];
37  uint8_t resultData[64];
38  BitBuffer_t cmdBuf;
39  osd_raw_cmd_t osd_cmd;
40  int err;
41 
42  if (Version == NULL)
43  return -EINVAL;
44 
45  *Version = 0;
46  if (String)
47  String[0] = 0;
48 
49  BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
50  memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
51  osd_cmd.cmd_data = cmdData;
52  osd_cmd.result_data = resultData;
53  osd_cmd.result_len = sizeof(resultData);
56  osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
57  err = ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
58  if (err == 0)
59  {
60  if (osd_cmd.result_len > 0)
61  {
62  if (String)
63  {
64  uint8_t textLength = resultData[9];
65  if (textLength >= MaxLength)
66  textLength = MaxLength - 1;
67  memcpy(String, &resultData[10], textLength);
68  String[textLength] = 0;
69  }
70  *Version = (resultData[6] << 16)
71  | (resultData[7] << 8)
72  | resultData[8];
73  }
74  }
75  return err;
76 }
77 
78 int HdffCmdGetInterfaceVersion(int OsdDevice, uint32_t * Version, char * String,
79  uint32_t MaxLength)
80 {
81  uint8_t cmdData[8];
82  uint8_t resultData[64];
83  BitBuffer_t cmdBuf;
84  osd_raw_cmd_t osd_cmd;
85  int err;
86 
87  if (Version == NULL)
88  return -EINVAL;
89 
90  *Version = 0;
91  if (String)
92  String[0] = 0;
93 
94  BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
95  memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
96  osd_cmd.cmd_data = cmdData;
97  osd_cmd.result_data = resultData;
98  osd_cmd.result_len = sizeof(resultData);
101  osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
102  err = ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
103  if (err == 0)
104  {
105  if (osd_cmd.result_len > 0)
106  {
107  if (String)
108  {
109  uint8_t textLength = resultData[9];
110  if (textLength >= MaxLength)
111  textLength = MaxLength - 1;
112  memcpy(String, &resultData[10], textLength);
113  String[textLength] = 0;
114  }
115  *Version = (resultData[6] << 16)
116  | (resultData[7] << 8)
117  | resultData[8];
118  }
119  }
120  return err;
121 }
122 
123 int HdffCmdGetCopyrights(int OsdDevice, uint8_t Index, char * String,
124  uint32_t MaxLength)
125 {
126  uint8_t cmdData[8];
127  uint8_t resultData[280];
128  BitBuffer_t cmdBuf;
129  osd_raw_cmd_t osd_cmd;
130  int err;
131 
132  if (String == NULL)
133  return -EINVAL;
134 
135  String[0] = 0;
136 
137  BitBuffer_Init(&cmdBuf, cmdData, sizeof(cmdData));
138  memset(&osd_cmd, 0, sizeof(osd_raw_cmd_t));
139  osd_cmd.cmd_data = cmdData;
140  osd_cmd.result_data = resultData;
141  osd_cmd.result_len = sizeof(resultData);
144  BitBuffer_SetBits(&cmdBuf, 8, Index);
145  osd_cmd.cmd_len = HdffCmdSetLength(&cmdBuf);
146  err = ioctl(OsdDevice, OSD_RAW_CMD, &osd_cmd);
147  if (err == 0)
148  {
149  if (osd_cmd.result_len > 0)
150  {
151  uint8_t index = resultData[6];
152  uint8_t textLen = resultData[7];
153  if (index == Index && textLen > 0)
154  {
155  if (textLen >= MaxLength)
156  {
157  textLen = MaxLength - 1;
158  }
159  memcpy(String, resultData + 8, textLen);
160  String[textLen] = 0;
161  }
162  }
163  }
164  return err;
165 }
int HdffCmdGetFirmwareVersion(int OsdDevice, uint32_t *Version, char *String, uint32_t MaxLength)
void BitBuffer_SetBits(BitBuffer_t *BitBuffer, int NumBits, uint32_t Data)
Definition: bitbuffer.c:37
const void * cmd_data
Definition: hdffcmd_base.h:31
uint32_t HdffCmdSetLength(BitBuffer_t *MsgBuf)
Definition: hdffcmd_base.c:36
void BitBuffer_Init(BitBuffer_t *BitBuffer, uint8_t *Data, uint32_t MaxLength)
Definition: bitbuffer.c:28
void * result_data
Definition: hdffcmd_base.h:33
void HdffCmdBuildHeader(BitBuffer_t *MsgBuf, HdffMessageType_t MsgType, HdffMessageGroup_t MsgGroup, HdffMessageId_t MsgId)
Definition: hdffcmd_base.c:26
int HdffCmdGetCopyrights(int OsdDevice, uint8_t Index, char *String, uint32_t MaxLength)
#define OSD_RAW_CMD
Definition: hdffcmd_base.h:43
int HdffCmdGetInterfaceVersion(int OsdDevice, uint32_t *Version, char *String, uint32_t MaxLength)