添加重启、恢复出厂的udp指令实现
This commit is contained in:
@@ -13,12 +13,34 @@
|
||||
- (NSString *)description{
|
||||
|
||||
self.messagetype=@"00";
|
||||
self.massagelegth=@"48";
|
||||
self.massagelegth=@"39";
|
||||
self.functionCode=@"12";
|
||||
self.sendmacId = @"000000000000";
|
||||
self.resavemacId = @"000000000000";
|
||||
|
||||
return [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@", self.messagetype,self.functionCode,self.sendmacId,self.resavemacId,self.massagelegth,[dataContorl hexStringFromString:self.ssidName], [dataContorl hexStringFromString:self.pwd],[self crcCode]];
|
||||
return [NSString stringWithFormat:@"%@%@%@%@%@%@%@%@", self.messagetype,self.functionCode,self.sendmacId,self.resavemacId,self.massagelegth,[self zeroLeftPadding:[dataContorl hexStringFromString:self.ssidName]], [self zeroLeftPadding:[dataContorl hexStringFromString:self.pwd]],[self crcCode]];
|
||||
}
|
||||
|
||||
- (NSString *)ssidName {
|
||||
return [NSString stringWithFormat:@"%@\0", _ssidName];
|
||||
}
|
||||
|
||||
- (NSString *)pwd {
|
||||
return [NSString stringWithFormat:@"%@\0", _pwd];
|
||||
}
|
||||
|
||||
- (NSString *)zeroLeftPadding:(NSString *)origin {
|
||||
if (origin.length >= 40) {
|
||||
return [origin substringToIndex:40];
|
||||
} else {
|
||||
NSInteger left = 40 - origin.length;
|
||||
NSMutableString *str = [NSMutableString string];
|
||||
for (NSInteger index = 0; index < left; index++) {
|
||||
[str appendString:@"0"];
|
||||
}
|
||||
[str appendString:origin];
|
||||
return [str copy];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)crcCode {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
|
||||
@protocol IFishHotpotUDPHelperDelegate<NSObject>
|
||||
|
||||
@optional
|
||||
- (void)udpHelperMessage:(NSString *)msg;
|
||||
- (void)udpHelperCommandExecutedSuccess;
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,6 +27,8 @@
|
||||
|
||||
@property (nonatomic, weak) id<IFishHotpotUDPHelperDelegate> delegate;
|
||||
|
||||
-(void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd;
|
||||
- (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd;
|
||||
- (void)broadCastRestartCommand;
|
||||
- (void)broadCastRestCommand;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#import "LxGetCurrentIp.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "ConnectHotspotModel.h"
|
||||
#import "ResetDeviceModel.h"
|
||||
#import "RestartDeviceModel.h"
|
||||
|
||||
@interface IFishHotpotUDPHelper ()
|
||||
{
|
||||
@@ -38,6 +40,65 @@
|
||||
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(sendConnectHotspotSoketdata) userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)broadCastRestCommand {
|
||||
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(sendRestSocketData) userInfo:nil repeats:YES];
|
||||
}
|
||||
|
||||
- (void)sendRestSocketData {
|
||||
NSString* hostS = @"192.168.4.1";
|
||||
|
||||
self.clientSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||
//120.55.190.56 服务器IP 指令中用
|
||||
ResetDeviceModel *model = [ResetDeviceModel new];
|
||||
NSString *request=[NSString stringWithFormat:@"%@", model.description];
|
||||
|
||||
NSData *data=[dataContorl stringToHexData:request];
|
||||
|
||||
UInt16 port = 333;
|
||||
UInt16 bindPort = 9954;
|
||||
|
||||
NSError *error;
|
||||
|
||||
[self.clientSocket enableBroadcast:YES error:&error];
|
||||
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
|
||||
|
||||
//本地接收端口
|
||||
[self.clientSocket bindToPort:bindPort error:&error];
|
||||
|
||||
[self.clientSocket receiveWithTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
- (void)broadCastRestartCommand {
|
||||
self.loopTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(sendRestartSocketData) userInfo:nil repeats:YES];
|
||||
|
||||
}
|
||||
|
||||
- (void)sendRestartSocketData {
|
||||
NSString* hostS = @"192.168.4.1";
|
||||
|
||||
self.clientSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||
//120.55.190.56 服务器IP 指令中用
|
||||
RestartDeviceModel *model = [RestartDeviceModel new];
|
||||
NSString *request=[NSString stringWithFormat:@"%@", model.description];
|
||||
|
||||
NSData *data=[dataContorl stringToHexData:request];
|
||||
|
||||
UInt16 port = 333;
|
||||
UInt16 bindPort = 9954;
|
||||
|
||||
NSError *error;
|
||||
|
||||
[self.clientSocket enableBroadcast:YES error:&error];
|
||||
|
||||
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
|
||||
|
||||
//本地接收端口
|
||||
[self.clientSocket bindToPort:bindPort error:&error];
|
||||
|
||||
[self.clientSocket receiveWithTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
-(void)sendConnectHotspotSoketdata{
|
||||
NSString* hostS = @"192.168.4.1";
|
||||
|
||||
@@ -76,6 +137,9 @@
|
||||
NSLog(@"port%hu",port);
|
||||
AppDelegate *app =(AppDelegate*)[UIApplication sharedApplication].delegate;
|
||||
[app.window makeToast:[NSString stringWithFormat:@"收到答复:%@", result]];
|
||||
if ([self.delegate respondsToSelector:@selector(udpHelperCommandExecutedSuccess)]) {
|
||||
[self.delegate udpHelperCommandExecutedSuccess];
|
||||
}
|
||||
[self.loopTimer invalidate];
|
||||
return YES;
|
||||
|
||||
@@ -91,7 +155,6 @@
|
||||
-(void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag{
|
||||
|
||||
NSLog(@"didSendData");
|
||||
[self postmsg:@"发送成功"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// ResetDeviceModel.h
|
||||
// Ifish
|
||||
//
|
||||
// Created by Minghao Xue on 2018/8/6.
|
||||
// Copyright © 2018年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "baseModel.h"
|
||||
|
||||
@interface ResetDeviceModel : baseModel
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// ResetDeviceModel.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by Minghao Xue on 2018/8/6.
|
||||
// Copyright © 2018年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ResetDeviceModel.h"
|
||||
|
||||
@implementation ResetDeviceModel
|
||||
|
||||
- (NSString *)description{
|
||||
|
||||
self.messagetype=@"00";
|
||||
self.massagelegth=@"11";
|
||||
self.functionCode=@"14";
|
||||
self.sendmacId = @"000000000000";
|
||||
self.resavemacId = @"000000000000";
|
||||
|
||||
return [NSString stringWithFormat:@"%@%@%@%@%@%@", self.messagetype,self.functionCode,self.sendmacId,self.resavemacId,self.massagelegth,[self crcCode]];
|
||||
}
|
||||
|
||||
- (NSString *)crcCode {
|
||||
return @"0000";
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// RestartDeviceModel.h
|
||||
// Ifish
|
||||
//
|
||||
// Created by Minghao Xue on 2018/8/6.
|
||||
// Copyright © 2018年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "baseModel.h"
|
||||
|
||||
@interface RestartDeviceModel : baseModel
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// RestartDeviceModel.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by Minghao Xue on 2018/8/6.
|
||||
// Copyright © 2018年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RestartDeviceModel.h"
|
||||
|
||||
@implementation RestartDeviceModel
|
||||
|
||||
- (NSString *)description{
|
||||
|
||||
self.messagetype=@"00";
|
||||
self.massagelegth=@"11";
|
||||
self.functionCode=@"13";
|
||||
self.sendmacId = @"000000000000";
|
||||
self.resavemacId = @"000000000000";
|
||||
|
||||
return [NSString stringWithFormat:@"%@%@%@%@%@%@", self.messagetype,self.functionCode,self.sendmacId,self.resavemacId,self.massagelegth,[self crcCode]];
|
||||
}
|
||||
|
||||
- (NSString *)crcCode {
|
||||
return @"0000";
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user