添加重启、恢复出厂的udp指令实现

This commit is contained in:
xuemh
2018-08-06 22:35:06 +08:00
parent 4546e0b981
commit 1028ffa9ac
12 changed files with 209 additions and 27 deletions
@@ -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:@"发送成功"];
}