From 50628a8404f9aadcfc2836bbe8dc6e75924d5580 Mon Sep 17 00:00:00 2001 From: kai60 Date: Sat, 21 May 2022 21:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E4=B8=80=E9=94=AE=E5=96=82?= =?UTF-8?q?=E9=B1=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ifish/Utinitys/dataUnity/dataContorl.h | 6 ++ Ifish/Utinitys/dataUnity/dataContorl.m | 33 ++++++- .../XuTo/Xuanduo2TimerModel.h | 12 +++ .../XuTo/Xuanduo2TimerModel.m | 6 ++ .../XuTo/XuanduofishFeedViewController.m | 97 +++++++------------ Ifish/views/mypicView/remindCyclePic.m | 8 ++ 6 files changed, 98 insertions(+), 64 deletions(-) diff --git a/Ifish/Utinitys/dataUnity/dataContorl.h b/Ifish/Utinitys/dataUnity/dataContorl.h index b818674..ba2ed4c 100644 --- a/Ifish/Utinitys/dataUnity/dataContorl.h +++ b/Ifish/Utinitys/dataUnity/dataContorl.h @@ -13,6 +13,12 @@ +(NSData *) stringToHexData:(NSString*)string; +(NSString *)hexStringFromString:(NSString *)string; +(NSString *)ToHex:(long long int)tmpid; +/// 十进制转二进制,补全,截取特定位置 +/// @param decimal 十进制 +/// @param location 截取位数从末尾开始1,2,3... +/// @param totalLength 补全位数,例如8位,4位,传0不会处理 ++ (NSString *)getBinaryByDecimal:(NSInteger)decimal location:(NSInteger)location totalLength:(NSInteger)totalLength; + +(UInt64)hexToTen:(NSString*)str; +(NSString *)groupNumberTohex:(NSInteger)number; +(NSString *)stringFromHexString:(NSString *)hexString; diff --git a/Ifish/Utinitys/dataUnity/dataContorl.m b/Ifish/Utinitys/dataUnity/dataContorl.m index ab940ec..15b11d8 100644 --- a/Ifish/Utinitys/dataUnity/dataContorl.m +++ b/Ifish/Utinitys/dataUnity/dataContorl.m @@ -109,7 +109,38 @@ } return str; } - ++ (NSString *)getBinaryByDecimal:(NSInteger)decimal location:(NSInteger)location totalLength:(NSInteger)totalLength { + NSString *binary = @""; + if (decimal != 0) { + while (decimal) { + binary = [[NSString stringWithFormat:@"%ld", decimal % 2] stringByAppendingString:binary]; + if (decimal / 2 < 1) { + break; + } + decimal = decimal / 2 ; + } + // 根据需求传位数 + if (totalLength > 0) { + if (binary.length % totalLength != 0) { + NSMutableString *mStr = [[NSMutableString alloc]init]; + for (int i = 0; i < totalLength - binary.length % totalLength; i++) { + [mStr appendString:@"0"]; + } + binary = [mStr stringByAppendingString:binary]; + } + } + // 保护 + if (binary.length > 0 && binary.length >= location) { + // 截取特定位置的二进制字符 + binary = [binary substringWithRange:NSMakeRange(binary.length-location, 1)]; + } else { + binary = @"0"; + } + } else { + binary = @"0"; + } + return binary; +} /// 1 - 10组 +(NSString *)groupNumberTohex:(NSInteger)number{ NSString *str = @""; diff --git a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.h b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.h index cf30bd5..89d2b78 100644 --- a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.h +++ b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.h @@ -60,6 +60,18 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) NSString *closeTime; +@end +@interface XuanduoFishFeedModel : NSObject + +/// 6路灯的选择,11111100 从高到低 表示是否选择 二进制 +@property (nonatomic, strong) NSString *lightChooseStatus; +//表示时间1~60 +@property (nonatomic, strong) NSString *feedTime; +//6路灯的控制状态 11111100 从高到低 0关,1开。 二进制 +@property (nonatomic, strong) NSString *lightOpenStatus; + + + @end @interface XuanduoRecoveryModel : NSObject diff --git a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.m b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.m index a6b7ca4..1df58c5 100644 --- a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.m +++ b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/Xuanduo2TimerModel.m @@ -29,4 +29,10 @@ @end +@implementation XuanduoFishFeedModel + + + +@end + diff --git a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/XuanduofishFeedViewController.m b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/XuanduofishFeedViewController.m index 29c7ba2..a3d4a4b 100644 --- a/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/XuanduofishFeedViewController.m +++ b/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/XuTo/XuanduofishFeedViewController.m @@ -49,6 +49,7 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; @property (nonatomic,strong) NSMutableDictionary *timeDic; @property(nonatomic,copy) NSString *nextChangeDateLabel; @property(nonatomic,strong) MyHud *XuTohud; +@property(nonatomic,strong)XuanduoFishFeedModel*fishFeedModel; @end @@ -228,9 +229,9 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; cell.titleLabel.text = model.title; NSLog(@"wendu str = %@",_wenduString); model.temperatureLabel = _wenduString; - cell.temperaturelabel.text = model.temperatureLabel; + cell.temperaturelabel.text = [NSString stringWithFormat:@"%ld分钟",(self.fishFeedModel?[dataContorl hexToTen:self.fishFeedModel.feedTime]:0)]; [cell.temPSwitch addTarget:self action:@selector(xuTotempSwitchAction:) forControlEvents:UIControlEventTouchUpInside]; - cell.temperaturelabel.hidden=YES; + // cell.temperaturelabel.hidden=YES; cell.temPSwitch.hidden=YES; cell.icon.hidden=NO; cell.icon.image=[UIImage imageNamed:@"喂鱼"]; @@ -484,54 +485,15 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _indexPath = indexPath; - if (indexPath.section==0) { -// _mypicView=[[MyPickerView alloc]init]; -// -// _mypicView.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); -// [self.view.window addSubview:_mypicView]; -// [_mypicView.sureButton addTarget:self action:@selector(mypicViewRemoveByDone) forControlEvents:UIControlEventTouchUpInside]; -// [self temperatureMainQueue]; - - }else if (indexPath.section==1){ + if (indexPath.section==0&&indexPath.row==0){ //换水提醒日期选择 _remindPic=[[remindCyclePic alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height) type:self.currentdevice.type]; - + _remindPic.type=@"temp"; _remindPic.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); _remindPic.type=self.currentdevice.type; [self.view.window addSubview:_remindPic]; [_remindPic.sureBtn addTarget:self action:@selector(xuToremindCyclePicDone) forControlEvents:UIControlEventTouchUpInside]; [self huanShuiMainQueue]; - }else if(indexPath.section-2==_titieArr.count){ - //恒温设置 - _remindPic=[[remindCyclePic alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height) type:@"temp"]; - _remindPic.type=@"temp"; - - _remindPic.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); - [self.view.window addSubview:_remindPic]; - [_remindPic.sureBtn addTarget:self action:@selector(xuToremindCyclePicDone) forControlEvents:UIControlEventTouchUpInside]; - [self huanShuiMainQueue]; - }else { - SetTimerCell *cell = [self.tableView cellForRowAtIndexPath:_indexPath]; - if ([cell isKindOfClass:[PlusTableViewCell class]]) { - return; - } - else if([cell isKindOfClass:[SetTimerCell class]]&&[cell.model isKindOfClass:[XuanduoCycleModel class]]) - { - //恒温设置 - _cycleModel=cell.model; - _remindPic=[[remindCyclePic alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height) type:@"cycle"]; - _remindPic.type=@"cycle"; - - _remindPic.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height); - [self.view.window addSubview:_remindPic]; - [_remindPic.sureBtn addTarget:self action:@selector(xuToremindCyclePicDone) forControlEvents:UIControlEventTouchUpInside]; - [self huanShuiMainQueue]; - } - else - { - [self addTimer:nil]; - - } } } @@ -1610,27 +1572,21 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; NSString*string1=[dataContorl dataToHexString:data]; NSLog(@"return str == %@",string1); NSString *readTimer = [string1 substringToIndex:4]; - if (_selectSection-2<_titieArr.count && _selectSection-2>=0 && [readTimer isEqualToString:@"0116"]) { - if (!_timerModel) { - _timerModel = [[Xuanduo2TimerModel alloc] init]; - _timerModel.groupModelArr = [NSMutableArray array]; - }else { - [_timerModel.groupModelArr removeAllObjects]; - } - [Xuanduo2DataUtility readTimerSocketDataWithBackMsgModel:_timerModel addWithBackStr:string1 type:self.currentdevice.type]; - NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]]; - [dataArr removeAllObjects]; - [dataArr addObject:plusflag]; - [dataArr addObjectsFromArray:_timerModel.groupModelArr]; - BOOL havePlus = [dataArr containsObject:plusflag]; - if (havePlus && dataArr.count > 10) { - [dataArr removeObjectAtIndex:0]; - }else if (!havePlus && dataArr.count < 10){ - [dataArr insertObject:plusflag atIndex:0]; - } - NSLog(@"dataarr.count = %ld",dataArr.count); - + if ([readTimer isEqualToString:@"0116"]) + { + NSString*lightNumber=[string1 substringWithRange:NSMakeRange(30, 2)]; + if ([lightNumber isEqualToString:@"09"])//定时 + { + XuanduoFishFeedModel*fishFeedModel=[[XuanduoFishFeedModel alloc]init]; + fishFeedModel.feedTime=[string1 substringWithRange:NSMakeRange(32, 2)]; + fishFeedModel.lightChooseStatus=[string1 substringWithRange:NSMakeRange(34, 1)]; + fishFeedModel.lightOpenStatus=[string1 substringWithRange:NSMakeRange(35, 1)]; + + self.fishFeedModel=fishFeedModel; + + + } } else if (_selectSection-2<_titieArr.count && _selectSection-2>=0 && [readTimer isEqualToString:@"0119"]) { @@ -1660,6 +1616,21 @@ static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; -(void)ifishDeviceLogInSuccees{ + //读取一键喂鱼状态 + ReadTimerModel *readModel = [[ReadTimerModel alloc] init]; + readModel.sendmacId =self.currentdevice.macAddress; + readModel.resavemacId = self.currentdevice.macAddress; + readModel.crc16str=@"0000"; + readModel.selectorNumber=@"09"; + NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str]; + + + + NSData*readData=[dataContorl stringToHexData:readString]; + [[Socketsingleton sharedInstance] soketWriteData:readData]; + [_indicatorView startAnimating]; + + } -(void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket{ diff --git a/Ifish/views/mypicView/remindCyclePic.m b/Ifish/views/mypicView/remindCyclePic.m index ace172c..5382d38 100644 --- a/Ifish/views/mypicView/remindCyclePic.m +++ b/Ifish/views/mypicView/remindCyclePic.m @@ -52,6 +52,9 @@ else if ([self.type isEqualToString:@"temp"]) { title.text=@"恒温设置"; } + else if ([self.type isEqualToString:@"feed"]) { + title.text=@"喂鱼时长"; + } else if ([self.type isEqualToString:@"cycle"]) { title.text=@"杀菌持续时长"; } @@ -125,6 +128,11 @@ _picArr=@[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13" { _picArr=@[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30"]]; } + else if ([self.type isEqualToString:@"feed"]) + { + _picArr=@[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",@"57",@"58",@"59",@"60"]]; + } + }