更新时间:2025-01-13 02:48:15下载pdf
扫地机 Peer-to-Peer(P2P)能力提供 P2P 下载通道,来获取扫地机上的地图和清扫路线数据。由于数据直接来源于设备点对点的直传,所以无需将实时地图与数据上传至云存储服务器再下载,从而达到数据传输速度更快、更节省云存储成本的目的。
ThingSmartSweeperP2PManager *p2pManager = [[ThingSmartSweeperP2PManager alloc] init];
接口说明
- (void)initP2PSDKWithUserId:(nullable NSString *)userId
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
参数 | 说明 |
---|---|
userId | 用户 ID |
success | 建立 P2P 连接成功回调 |
failure | 建立 P2P 连接失败回调 |
代码示例
[self.p2pManager initP2PSDKWithUserId:userId success:^{
[self appendLogStr:@"p2p init success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"p2p init fail"];
}];
接口说明
- (void)deInitSDK:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
代码示例
[self.p2pManager deInitSDK:^{
[self appendLogStr:@"deInitSDK success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"deInitSDK failure"];
}];
接口说明
- (void)connectDevice:(ThingSmartSweeperP2PConnectionParams*)params
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
ThingSmartSweeperP2PConnectionParams
参数 | 说明 |
---|---|
mode | 连接模式
|
timeout | 超时时长,单位:ms 值为 0 会设置成默认值 |
代码示例
ThingSmartSweeperP2PConnectionParams *params = [ThingSmartSweeperP2PConnectionParams new];
params.deviceId = @"6c40873f680224bc01ssjl";
params.mode = 0;
params.timeout = 15000;
[self.p2pManager connectDevice:params success:^{
[self appendLogStr:@"p2p connect success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"p2p connect fail"];
}];
接口说明
- (void)disconnectDevice:(NSString*)devId
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
参数 | 说明 |
---|---|
devId | 设备 ID |
success | 断开 P2P 连接成功回调 |
failure | 断开 P2P 连接失败回调 |
代码示例
[self.p2pManager disconnectDevice:devId success:^{
[self appendLogStr:@"breakP2PBtn success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"breakP2PBtn success"];
}];
接口说明
- (void)isP2PActive:(NSString*)devId
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
参数 | 说明 |
---|---|
devId | 设备 ID |
success | P2P 已连接 |
failure | P2P 未连接 |
代码示例
[self.p2pManager isP2PActive:devId success:^{
[self appendLogStr:@"isP2PActive function success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"isP2PActive function fail"];
}];
通过 queryAlbumFileIndexs
获取地图文件列表后,再调用本接口下载最终地图文件。
文件名后缀为 .stream
表示持续下载设备产生的数据,直到设备自动停止发送数据,或调用 cancelDownload
取消下载。
接口说明
- (void)downloadFile:(ThingSmartSweeperP2PDownloadFile*)params
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
ThingSmartSweeperP2PDownloadFile
参数 | 说明 |
---|---|
deviceId | 设备 ID |
albumName | 默认值 ipc_sweeper_robot |
filePath | 下载文件在 App 的本地存储路径 |
jsonfiles | 下载的文件,格式如:{"files":["filesname1", "filesname2", "filesname3" ]} |
代码示例
ThingSmartSweeperP2PDownloadFile *params = [ThingSmartSweeperP2PDownloadFile new];
params.deviceId = @"6c408731420094bc01skjl";
params.albumName = @"ipc_sweeper_robot";
params.filePath = [ThingSmartSweeperP2PUtil sweeper_directoryPath:@"6c408731420094bc01skjl" albumName:[ThingSmartSweeperP2PUtil sweeper_filealbumNameWithDownloadType:1]];
NSDictionary *reqData = @{@"files":self.fileList};
NSString *jsonfiles = [reqData yy_modelToJSONString];
params.jsonfiles = jsonfiles;
[self.p2pManager downloadFile:params success:^{
[self appendLogStr:@"downloadFile success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"downloadFile fail"];
}];
接口说明
- (void)cancelDownloadTask:(NSString*)devId
success:(void (^)(void))success
failure:(void (^)(NSError * _Nullable error))failure;
代码示例
[self.p2pManager cancelDownloadTask:@"6c40873f680094bc01skjl" success:^{
[self appendLogStr:@"cancel downloadTask success"];
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"cancel downloadTask fail"];
}];
接口说明
- (void)queryAlbumFileIndexs:(ThingSmartSweeperP2PAlbum*)params
success:(void (^)(ThingSmartSweeperP2PAlbumFileIndexs *data))success
failure:(void (^)(NSError * _Nullable error))failure;
参数说明
ThingSmartSweeperP2PAlbum
参数 | 说明 |
---|---|
deviceId | 设备 ID |
albumName | 和设备端约定字段 |
ThingSmartSweeperP2PAlbumFileIndexs
参数 | 说明 |
---|---|
count | 文件个数 |
items | 文件索引 |
其他参数说明
参数 | 说明 |
---|---|
params | 入参模型 |
success | 成功回调 |
failure | 失败回调 |
代码示例
ThingSmartSweeperP2PAlbum *params = [ThingSmartSweeperP2PAlbum new];
params.deviceId = @"6c40873ss83394b66501skjl";
params.albumName = @"ipc_sweeper_robot";
[self.p2pManager queryAlbumFileIndexs:params
success:^(ThingSmartSweeperP2PAlbumFileIndexs * _Nonnull data) {
NSMutableArray *items = [NSMutableArray array];
for (ThingSmartSweeperP2PAlbumFileIndex *fileIndex in data.items) {
if (fileIndex.filename && [fileIndex.filename hasSuffix:@"stream"]) {
[items addObject:fileIndex.filename];
}
}
self.fileList = items;
} failure:^(NSError * _Nullable error) {
[self appendLogStr:@"queryAlbumFileIndexs fail"];
}];
接口说明
@property (nonatomic, weak) id <ThingSmartSweeperP2PManagerDelegate> p2pFileManagerDelegate;
回调类说明
@protocol ThingSmartSweeperP2PManagerDelegate <NSObject>
@optional
/**
* 连接状态改变回调
*
* @param model 状态模型
*/
- (void)sessionStatusChangeWithModel:(ThingSmartSweeperP2PSessionStatus *)model;
/**
* 上传进度回调
*
* @param progress 进度模型
*/
- (void)uploadProgressUpdateWithModel:(ThingSmartSweeperFileManagerProgress *)progress;
/**
* 单个文件下载进度回调
*
* @param progress 进度模型
*/
- (void)downloadProgressUpdateWithModel:(ThingSmartSweeperFileDownloadProgress *)progress;
/**
* 下载总进度回调
*
* @param progress 进度模型
*/
- (void)downloadTotalProgressUpdateWithModel:(ThingSmartSweeperFileDownloadTotalProgress *)progress;
/**
* 单文件下载完成事件
*
* @param model 下载完成数据模型
*/
- (void)fileDownloadCompleteWithModel:(ThingSmartSweeperFileDownloadCompletion *)model;
/**
* 收到数据包事件
*
* @param model 数据包模型
*/
- (void)streamPacketReceiveWithModel:(ThingSmartSweeperFileManagerPacketReceived *)model;
@end
参数说明
ThingSmartSweeperP2PSessionStatus
参数 | 说明 |
---|---|
deviceId | 设备 ID |
status | 状态值,小于 0 为断开连接,其他见 P2P SDK 错误码 |
ThingSmartSweeperFileDownloadCompletion
参数 | 说明 |
---|---|
deviceId | 设备 ID |
fileName | 文件名 |
index | 索引 |
ThingSmartSweeperFileDownloadProgress
参数 | 说明 |
---|---|
deviceId | 设备 ID |
fileName | 文件名 |
progress | 进度 |
ThingSmartSweeperFileDownloadTotalProgress
参数 | 说明 |
---|---|
deviceId | 设备 ID |
progress | 进度 |
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈