添加重启、恢复出厂的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

View File

@ -2466,6 +2466,8 @@
E5212236210760A700BA24C5 /* SettingResetViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E5212234210760A600BA24C5 /* SettingResetViewController.xib */; };
E52B400521042ED2003BBA3E /* ConnectHotspotTipViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E52B400321042ED2003BBA3E /* ConnectHotspotTipViewController.m */; };
E52B400621042ED2003BBA3E /* ConnectHotspotTipViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E52B400421042ED2003BBA3E /* ConnectHotspotTipViewController.xib */; };
E5317A1321188F170014AFDD /* ResetDeviceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E5317A1221188F170014AFDD /* ResetDeviceModel.m */; };
E5317A1621188F8A0014AFDD /* RestartDeviceModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E5317A1521188F8A0014AFDD /* RestartDeviceModel.m */; };
E547870B20728F390060C2C2 /* back_btn@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E547870A20728F380060C2C2 /* back_btn@2x.png */; };
E547870F2073192E0060C2C2 /* introlImage_iphonex_1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = E547870C2073192D0060C2C2 /* introlImage_iphonex_1.jpg */; };
E54787102073192E0060C2C2 /* introlImage_iphonex_2.jpg in Resources */ = {isa = PBXBuildFile; fileRef = E547870D2073192D0060C2C2 /* introlImage_iphonex_2.jpg */; };
@ -6265,6 +6267,10 @@
E52B400221042ED2003BBA3E /* ConnectHotspotTipViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConnectHotspotTipViewController.h; sourceTree = "<group>"; };
E52B400321042ED2003BBA3E /* ConnectHotspotTipViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConnectHotspotTipViewController.m; sourceTree = "<group>"; };
E52B400421042ED2003BBA3E /* ConnectHotspotTipViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConnectHotspotTipViewController.xib; sourceTree = "<group>"; };
E5317A1121188F170014AFDD /* ResetDeviceModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ResetDeviceModel.h; sourceTree = "<group>"; };
E5317A1221188F170014AFDD /* ResetDeviceModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ResetDeviceModel.m; sourceTree = "<group>"; };
E5317A1421188F8A0014AFDD /* RestartDeviceModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RestartDeviceModel.h; sourceTree = "<group>"; };
E5317A1521188F8A0014AFDD /* RestartDeviceModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RestartDeviceModel.m; sourceTree = "<group>"; };
E547870A20728F380060C2C2 /* back_btn@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "back_btn@2x.png"; sourceTree = "<group>"; };
E547870C2073192D0060C2C2 /* introlImage_iphonex_1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = introlImage_iphonex_1.jpg; sourceTree = "<group>"; };
E547870D2073192D0060C2C2 /* introlImage_iphonex_2.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = introlImage_iphonex_2.jpg; sourceTree = "<group>"; };
@ -9642,6 +9648,10 @@
883E781C1D48A5E50030E075 /* SecondConnectWifiController.xib */,
883E781D1D48A5E50030E075 /* SelectDeviceViewController.h */,
883E781E1D48A5E50030E075 /* SelectDeviceViewController.m */,
E5317A1421188F8A0014AFDD /* RestartDeviceModel.h */,
E5317A1521188F8A0014AFDD /* RestartDeviceModel.m */,
E5317A1121188F170014AFDD /* ResetDeviceModel.h */,
E5317A1221188F170014AFDD /* ResetDeviceModel.m */,
883E781F1D48A5E50030E075 /* SetViewController.h */,
883E78201D48A5E50030E075 /* SetViewController.m */,
E567026B21187E7C00E61993 /* ConnectHotspotModel.h */,
@ -16118,6 +16128,7 @@
8829582B1DC18CD100E9DDD7 /* AFNOHeaderHttpTool.m in Sources */,
E52122302107609500BA24C5 /* RestartViewController.m in Sources */,
886185CD1EF255F900459AD1 /* XuToControlNameViewController.m in Sources */,
E5317A1321188F170014AFDD /* ResetDeviceModel.m in Sources */,
881671FC1EA5DE2B00BEBF23 /* UMAssetsCollectionCheckMarkView.m in Sources */,
881477E61E71091300BFB79C /* IfishTaskModel.m in Sources */,
88C1B2BE1DD1749F00C2C99A /* IfishKanKanListViewController.m in Sources */,
@ -16325,6 +16336,7 @@
88602A3C1E10BC3500F3DB5D /* NIMCellLayoutConfig.m in Sources */,
882C85A61EB03759001CC414 /* GoldConvertDetailViewCell.m in Sources */,
881477EA1E711B4D00BFB79C /* IfishTaskViewCell.m in Sources */,
E5317A1621188F8A0014AFDD /* RestartDeviceModel.m in Sources */,
88602A591E10BC3500F3DB5D /* NIMTeamCardRowItem.m in Sources */,
886EAC5C1E2DC87E00A4DF27 /* IfishShopInfo.m in Sources */,
886028711E10BB1100F3DB5D /* NSNumberFormatter+CTAssetsPickerController.m in Sources */,

View File

@ -7,8 +7,9 @@
//
#import "RestartViewController.h"
#import "IFishHotpotUDPHelper.h"
@interface RestartViewController ()
@interface RestartViewController ()<IFishHotpotUDPHelperDelegate>
@end
@ -19,19 +20,15 @@
self.title = @"重启设备";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (IBAction)restart:(id)sender {
[IFishHotpotUDPHelper sharedInstance].delegate = self;
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
}
/*
#pragma mark - Navigation
#pragma mark - IFishHotpotUDPHelperDelegate
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
- (void)udpHelperCommandExecutedSuccess {
[self.view makeToast:@"设备即将重启"];
}
*/
@end

View File

@ -112,6 +112,9 @@
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="restart:" destination="-1" eventType="touchUpInside" id="JAB-MM-NYi"/>
</connections>
</button>
</subviews>
<constraints>

View File

@ -7,8 +7,9 @@
//
#import "SettingResetViewController.h"
#import "IFishHotpotUDPHelper.h"
@interface SettingResetViewController ()
@interface SettingResetViewController ()<IFishHotpotUDPHelperDelegate>
@end
@ -19,20 +20,15 @@
self.title = @"恢复出厂设置";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (IBAction)reset:(id)sender {
[IFishHotpotUDPHelper sharedInstance].delegate = self;
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
}
/*
#pragma mark - Navigation
#pragma mark - IFishHotpotUDPHelperDelegate
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
- (void)udpHelperCommandExecutedSuccess {
[self.view makeToast:@"设备即将重置"];
}
*/
@end

View File

@ -112,6 +112,9 @@
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="reset:" destination="-1" eventType="touchUpInside" id="XwX-J9-wjl"/>
</connections>
</button>
</subviews>
<constraints>

View File

@ -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 {

View File

@ -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

View File

@ -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:@"发送成功"];
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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