未验证 提交 ca7a91ad 编写于 作者: O openharmony_ci 提交者: Gitee

!15221 翻译完成:14047 【分布式硬件DM】示例代码问题修改

Merge pull request !15221 from wusongqing/TR14047
...@@ -78,6 +78,7 @@ Defines device information. ...@@ -78,6 +78,7 @@ Defines device information.
| deviceType | [DeviceType](#devicetype) | Yes | Device type. | | deviceType | [DeviceType](#devicetype) | Yes | Device type. |
| networkId<sup>8+</sup> | string | Yes | Network ID of the device. | | networkId<sup>8+</sup> | string | Yes | Network ID of the device. |
| range<sup>9+</sup> | number | Yes | Distance between the device (discovered device) and the device that initiates device discovery. | | range<sup>9+</sup> | number | Yes | Distance between the device (discovered device) and the device that initiates device discovery. |
| authForm<sup>10+</sup> | [AuthForm](#authform) | Yes | Authentication type of the device. |
## DeviceType ## DeviceType
...@@ -95,6 +96,18 @@ Enumerates the device types. ...@@ -95,6 +96,18 @@ Enumerates the device types.
| CAR | 0x83 | Car. | | CAR | 0x83 | Car. |
| UNKNOWN_TYPE | 0 | Unknown device type.| | UNKNOWN_TYPE | 0 | Unknown device type.|
## AuthForm
Enumerates the device authentication types.
**System capability**: SystemCapability.DistributedHardware.DeviceManager
| Name | Value | Description |
| ------------------- | ---- | --------------- |
| INVALID_TYPE | -1 | No authentication.|
| PEER_TO_PEER | 0 | Point-to-point authentication for devices without accounts. |
| IDENTICAL_ACCOUNT | 1 | Authentication for devices using the same account. |
| ACROSS_ACCOUNT | 2 | Authentication for devices using different accounts.|
## DeviceStateChangeAction ## DeviceStateChangeAction
...@@ -588,8 +601,9 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -588,8 +601,9 @@ For details about the error codes, see [Device Management Error Codes](../errorc
**Example** **Example**
```js ```js
// The subscribeId input must be the same as that automatically generated in startDeviceDiscovery.
try { try {
// stopDeviceDiscovery and startDeviceDiscovery must be used in pairs, and the input parameter **subscribeId** passed in them must be the same.
var subscribeId = 12345;
dmInstance.stopDeviceDiscovery(subscribeId); dmInstance.stopDeviceDiscovery(subscribeId);
} catch (err) { } catch (err) {
console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); console.error("stopDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
...@@ -630,7 +644,7 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -630,7 +644,7 @@ For details about the error codes, see [Device Management Error Codes](../errorc
"publishId": publishId, "publishId": publishId,
"mode": 0xAA, // Active discovery "mode": 0xAA, // Active discovery
"freq": 2, // High frequency "freq": 2, // High frequency
"ranging": 1 // The device supports reporting the distance to the discovery initiator. "ranging": true // The device supports reporting the distance to the discovery initiator.
}; };
try { try {
dmInstance.publishDeviceDiscovery(publishInfo); // A callback is invoked to notify the application when the device information is published. dmInstance.publishDeviceDiscovery(publishInfo); // A callback is invoked to notify the application when the device information is published.
...@@ -666,8 +680,9 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -666,8 +680,9 @@ For details about the error codes, see [Device Management Error Codes](../errorc
**Example** **Example**
```js ```js
// The publishId input must be the same as that automatically generated in publishDeviceDiscovery.
try { try {
// unPublishDeviceDiscovery and publishDeviceDiscovery must be used in pairs, and the input parameter **publishId** passed in them must be the same.
var publishId = 12345;
dmInstance.unPublishDeviceDiscovery(publishId); dmInstance.unPublishDeviceDiscovery(publishId);
} catch (err) { } catch (err) {
console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); console.error("unPublishDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
...@@ -708,11 +723,19 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -708,11 +723,19 @@ For details about the error codes, see [Device Management Error Codes](../errorc
var deviceInfo ={ var deviceInfo ={
"deviceId": "XXXXXXXX", "deviceId": "XXXXXXXX",
"deviceName": "", "deviceName": "",
deviceType: 0x0E "deviceType": 0x0E,
"networkId" : "xxxxxxx",
"range" : 0
}; };
let extraInfo = {
'targetPkgName': 'ohos.samples.xxx',
'appName': 'xxx',
'appDescription': 'xxx',
'business': '0'
}
let authParam = { let authParam = {
"authType": 1, // Authentication type. The value 1 means no account PIN authentication. 'authType': 1, // Authentication type. The value 1 means no account PIN authentication.
"extraInfo": {} 'extraInfo': extraInfo
} }
try { try {
dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => { dmInstance.authenticateDevice(deviceInfo, authParam, (err, data) => {
...@@ -756,6 +779,13 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -756,6 +779,13 @@ For details about the error codes, see [Device Management Error Codes](../errorc
```js ```js
try { try {
var deviceInfo ={
"deviceId": "XXXXXXXX",
"deviceName": "",
"deviceType": 0x0E,
"networkId" : "xxxxxxx",
"range" : 0
};
dmInstance.unAuthenticateDevice(deviceInfo); dmInstance.unAuthenticateDevice(deviceInfo);
} catch (err) { } catch (err) {
console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message); console.error("unAuthenticateDevice errCode:" + err.code + ",errMessage:" + err.message);
...@@ -792,7 +822,7 @@ For details about the error codes, see [Device Management Error Codes](../errorc ...@@ -792,7 +822,7 @@ For details about the error codes, see [Device Management Error Codes](../errorc
```js ```js
let authInfo = { let authInfo = {
"authType": 1, "authType": 1,
"token": xxxxxx, "token": 123456,
"extraInfo": {} "extraInfo": {}
} }
try { try {
...@@ -838,7 +868,7 @@ Sets a user operation. ...@@ -838,7 +868,7 @@ Sets a user operation.
operateAction = 5 - Confirm the input in the PIN input box. operateAction = 5 - Confirm the input in the PIN input box.
*/ */
let operation = 0; let operation = 0;
this.dmInstance.setUserOperation(operation, "extra") dmInstance.setUserOperation(operation, "extra")
} catch (err) { } catch (err) {
console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message); console.error("setUserOperation errCode:" + err.code + ",errMessage:" + err.message);
} }
...@@ -868,11 +898,8 @@ Subscribes to UI status changes. ...@@ -868,11 +898,8 @@ Subscribes to UI status changes.
dmInstance.on('uiStateChange', (data) => { dmInstance.on('uiStateChange', (data) => {
console.log("uiStateChange executed, dialog closed" + JSON.stringify(data)) console.log("uiStateChange executed, dialog closed" + JSON.stringify(data))
var tmpStr = JSON.parse(data.param) var tmpStr = JSON.parse(data.param)
this.isShow = tmpStr.verifyFailed var isShow = tmpStr.verifyFailed
console.log("uiStateChange executed, dialog closed" + this.isShow) console.log("uiStateChange executed, dialog closed" + isShow)
if (!this.isShow) {
this.destruction()
}
}); });
} catch (err) { } catch (err) {
console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message); console.error("uiStateChange errCode:" + err.code + ",errMessage:" + err.message);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册