Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c76307d0
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c76307d0
编写于
12月 15, 2021
作者:
W
wu-chengwen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: update subsys-usbservice-demo.md
Signed-off-by:
N
wu-chengwen
<
wuchengwen4@huawei.com
>
上级
7667de34
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
17 deletion
+19
-17
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
+19
-17
未找到文件。
zh-cn/device-dev/subsystems/subsys-usbservice-demo.md
浏览文件 @
c76307d0
# USB服务子系
统
使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
# USB服务子系使用实例<a name="ZH-CN_TOPIC_0000001092792986"></a>
```
...
...
@@ -22,16 +22,17 @@
#include "usb_server_proxy.h"
#include "usb_srv_client.h"
#define REQUESTYPE ((1 << 7) | (0 << 5) | (0 & 0x1f))
#define REQUESTCMD 6
#define VALUE (2 << 8) + 0
#define TIMEOUT 5000
#define ITFCLASS 10
#define ITFPROTOCOL 2
const int32_t REQUESTYPE = ((1 << 7) | (0 << 5) | (0 & 0x1f));
const int32_t REQUESTCMD = 6;
const int32_t VALUE = (2 << 8) + 0;
const int32_t TIMEOUT = 5000;
const int32_t ITFCLASS = 10;
const int32_t PRAMATYPE = 2;
const int32_t BUFFERLENGTH = 21;
void GetType(OHOS::USB::USBEndpoint tep, OHOS::USB::USBEndpoint &outEp, bool &outEpFlg)
void GetType(OHOS::USB::USBEndpoint
&
tep, OHOS::USB::USBEndpoint &outEp, bool &outEpFlg)
{
if ((tep.GetType() ==
2
)) {
if ((tep.GetType() ==
PRAMATYPE
)) {
if (tep.GetDirection() == 0) {
outEp = tep;
outEpFlg = true;
...
...
@@ -39,7 +40,7 @@ void GetType(OHOS::USB::USBEndpoint tep, OHOS::USB::USBEndpoint &outEp, bool &ou
}
}
bool
s
electEndpoint(OHOS::USB::USBConfig config,
bool
S
electEndpoint(OHOS::USB::USBConfig config,
std::vector<OHOS::USB::UsbInterface> interfaces,
OHOS::USB::UsbInterface &interface,
OHOS::USB::USBEndpoint &outEp,
...
...
@@ -50,7 +51,7 @@ bool selectEndpoint(OHOS::USB::USBConfig config,
std::vector<OHOS::USB::USBEndpoint> mEndpoints = tif.GetEndpoints();
for (int32_t j = 0; j < tif.GetEndpointCount(); ++j) {
OHOS::USB::USBEndpoint tep = mEndpoints[j];
if ((tif.GetClass() == ITFCLASS) && (tif.GetSubClass() == 0) && (tif.GetProtocol() ==
ITFPROTOCOL
)) {
if ((tif.GetClass() == ITFCLASS) && (tif.GetSubClass() == 0) && (tif.GetProtocol() ==
PRAMATYPE
)) {
GetType(tep, outEp, outEpFlg);
}
}
...
...
@@ -91,7 +92,7 @@ int CtrTransferTest(OHOS::USB::UsbSrvClient &g_usbClient, OHOS::USB::USBDevicePi
int ClaimTest(OHOS::USB::UsbSrvClient &g_usbClient,
OHOS::USB::USBDevicePipe &pip,
OHOS::USB::UsbInterface interface,
OHOS::USB::UsbInterface
&
interface,
bool interfaceFlg)
{
if (interfaceFlg) {
...
...
@@ -108,7 +109,7 @@ int ClaimTest(OHOS::USB::UsbSrvClient &g_usbClient,
int BulkTransferTest(OHOS::USB::UsbSrvClient &g_usbClient,
OHOS::USB::USBDevicePipe &pip,
OHOS::USB::USBEndpoint outEp,
OHOS::USB::USBEndpoint
&
outEp,
bool interfaceFlg,
bool outEpFlg)
{
...
...
@@ -116,8 +117,8 @@ int BulkTransferTest(OHOS::USB::UsbSrvClient &g_usbClient,
std::cout << "usb_device_test : << Bulk transfer start >> " << std::endl;
if (outEpFlg) {
uint8_t buffer[50] = "hello world 123456789";
std::vector<uint8_t> vData(buffer, buffer +
21
);
int ret = g_usbClient.BulkTransfer(pip, outEp, vData,
5000
);
std::vector<uint8_t> vData(buffer, buffer +
BUFFERLENGTH
);
int ret = g_usbClient.BulkTransfer(pip, outEp, vData,
TIMEOUT
);
if (ret != 0) {
std::cout << "Bulk transfer write failed width ret = " << ret << std::endl;
} else {
...
...
@@ -131,6 +132,7 @@ int BulkTransferTest(OHOS::USB::UsbSrvClient &g_usbClient,
int main(int argc, char **argv)
{
std::cout << "usb_device_test " << std::endl;
static OHOS::USB::UsbSrvClient &g_usbClient = OHOS::USB::UsbSrvClient::GetInstance();
// GetDevices
std::vector<OHOS::USB::UsbDevice> deviceList;
...
...
@@ -150,7 +152,7 @@ int main(int argc, char **argv)
OHOS::USB::USBEndpoint outEp;
bool interfaceFlg = false;
bool outEpFlg = false;
interfaceFlg =
s
electEndpoint(config, interfaces, interface, outEp, outEpFlg);
interfaceFlg =
S
electEndpoint(config, interfaces, interface, outEp, outEpFlg);
// OpenDevice
std::cout << "usb_device_test : << OpenDevice >> test begin -> " << std::endl;
...
...
@@ -176,7 +178,7 @@ int main(int argc, char **argv)
std::cout << "Close device failed width ret = " << ret << std::endl;
return OHOS::USB::UEC_SERVICE_INVALID_VALUE;
} else {
std::cout << "Close
d
evice success" << std::endl;
std::cout << "Close
D
evice success" << std::endl;
}
return 0;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录