// // Xuanduo2SettingController.m // Ifish // // Created by Alex on 2019/4/28. // Copyright © 2019 lianlian. All rights reserved. // #import "XuanduofishFeedViewController.h" #import "UINavigationBar+Background.h" #import "TemperatureSetCell.h" #import "ChangeWaterCell.h" #import "Xuanduo2Model.h" #import "TemperatureSetModel.h" #import "setWaringTpModel.h" #import "remindCyclePic.h" #import "MyPickerView.h" #import "PlusTableViewCell.h" #import "SetTimerCell.h" #import "XuanduoSectionHeaderView.h" #import "XuanduoSelectHeader.h" #import "MydatePickerView.h" #import "SetTimerModel.h" #import "ReadTimerModel.h" #import "Xuanduo2DataUtility.h" #import "Xuanduo2TimerModel.h" #import "IfishDeviceInfo.h" #import "NSString+Add.h" #import "XuToControlName.h" #import "UserExtendataArchaver.h" #import "TimerTypeTableViewCell.h" #define kBtnTag 500 #define kSwitchBtnTag 600 static NSString *temperatureCellid = @"TemperatureSetCell"; static NSString *changeWaterCellid = @"ChangeWaterCell"; static NSString *addCellid = @"PlusTableViewCell"; static NSString *plusflag = @"plusCell"; static NSString *setTimerflag = @"SetTimerCell"; static NSString *timerTypeFlag = @"TimerTypeTableViewCell"; @interface XuanduofishFeedViewController () @property(nonatomic,strong) setRemindWaterModel *waterInfmodel; @property(nonatomic,strong) Xuanduo2TimerModel *timerModel; @property(nonatomic,strong) XuanduoCycleModel *cycleModel; @property(nonatomic,strong)UITableView*tableView; @property (nonatomic,strong) NSMutableDictionary *timeDic; @property(nonatomic,copy) NSString *nextChangeDateLabel; @property(nonatomic,strong) MyHud *XuTohud; @property(nonatomic,strong)XuanduoFishFeedModel*fishFeedModel; @end @implementation XuanduofishFeedViewController { NSString *_wenduString; NSIndexPath *_indexPath; MyPickerView *_mypicView; NSArray *_titieArr; NSArray *_imgArr; remindCyclePic*_remindPic; BOOL _huanShuiSwitchIsOn; NSInteger _selectSection; MydatePickerView*_mydatepicView; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (_currentdevice) { [IFISHHTTPTOOL getRemindWaterInfWith:_currentdevice.deviceId huishuiInfo:^(setRemindWaterModel *remindModel) { self.waterInfmodel=remindModel; NSUserDefaults*defuat=[NSUserDefaults standardUserDefaults]; [defuat setInteger:self.waterInfmodel.remindcycle forKey:@"xuto2picResult"]; [defuat synchronize]; self.nextChangeDateLabel=self.waterInfmodel.remindDate; [self.tableView reloadData]; }]; } [Socketsingleton sharedInstance].communiteDelegate = self; //关闭打开的section _selectSection = -1; [self.tableView reloadData]; } - (void)viewDidLoad { [super viewDidLoad]; [self setup]; [self connect]; } - (void)viewWillDisappear:(BOOL)animated{ [_indicatorView stopAnimating]; } - (void)setup { [self.navigationController.navigationBar resetBackgroundImage]; NSString*title=@"喂鱼设置"; [self addTitleViewWithTitle:title]; [self refreshWithData:self.dataModel]; [self setupTable]; [self creatIndicatorView]; [Socketsingleton sharedInstance].communiteDelegate = self; } - (void)refreshWithData:(Xuanduo3fModel*)model { NSString*low = model.miniTemp; NSString*heigh = model.maxTemp; UInt64 lowten = [dataContorl hexToTen:low]; UInt64 heighten = [dataContorl hexToTen:heigh]; float formatlow = lowten/10; float formatheigh = heighten/10; _wenduString = [NSString stringWithFormat:@"%.0f~%.0f°C",formatlow,formatheigh]; } - (void)setupTable { self.view.backgroundColor=COLOR_MIAN; XuToControlName *name = [UserExtendataArchaver currentNewXuToControlName:self.currentdevice.macAddress]; if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { name=[UserExtendataArchaver currentPetsXuToControlName:self.currentdevice.macAddress]; } if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO5F]&&name.defaultName.length) { name.zengyangPump=@"蛋分器"; } // _titieArr = @[@"循环泵",@"增氧泵",@"灯光1",@"灯光2",@"造浪泵",@"杀菌灯"]; _titieArr = @[name.xunhuanPump,name.zengyangPump,name.light1,name.light2,name.zaolangPump,name.shajunLight]; _imgArr = @[@"循环棒",@"增氧泵",@"灯光1",@"灯光2",@"造浪",@"杀菌"]; if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO5F]&&name.defaultName.length) { _imgArr = @[@"循环棒",@"danfenqisetting",@"灯光1",@"灯光2",@"造浪",@"杀菌"]; } if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { _titieArr = @[name.xunhuanPump,name.zaolangPump,name.light1]; _imgArr = @[@"照明开",@"换气开",@"杀菌开"]; } _selectSection = -1; for (int i = 0; i<_titieArr.count; i++) { NSMutableArray *dataArr = [NSMutableArray arrayWithCapacity:0]; if (![_titieArr[i] isEqualToString:@"杀菌"]) { [dataArr addObject:plusflag]; } [self.timeDic setObject:dataArr forKey:_titieArr[i]]; } UITableView*tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 300) style:UITableViewStylePlain]; if (@available(iOS 15.0, *)) { tableView.sectionHeaderTopPadding=0; } tableView.delegate=self; tableView.dataSource=self; self.tableView=tableView; [self.view addSubview:tableView]; self.tableView.backgroundColor=COLOR_MIAN; self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone; [self.tableView registerNib:[UINib nibWithNibName:temperatureCellid bundle:nil] forCellReuseIdentifier:temperatureCellid]; [self.tableView registerNib:[UINib nibWithNibName:changeWaterCellid bundle:nil] forCellReuseIdentifier:changeWaterCellid]; [self.tableView registerNib:[UINib nibWithNibName:addCellid bundle:nil] forCellReuseIdentifier:addCellid]; //[self.tableView registerNib:[UINib nibWithNibName:timerTypeFlag bundle:nil] forCellReuseIdentifier:timerTypeFlag]; [self.tableView registerNib:[UINib nibWithNibName:setTimerflag bundle:nil] forCellReuseIdentifier:setTimerflag]; UILabel*label=[[UILabel alloc]initWithFrame:CGRectZero]; label.textColor=[UIColor whiteColor]; label.font=[UIFont systemFontOfSize:12]; label.numberOfLines=0; NSString*lightname=@"增氧泵"; if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO5F]) { lightname=@"蛋分器"; } label.text=[NSString stringWithFormat:@"将设备关联至一键喂鱼功能后,点击一键喂鱼开关时,所有关联的设备会同时按照设置好的操作执行,如您将循环泵、%@、灯光1三个设备关联至一键喂鱼功能,并将循环泵设置关闭,%@设置关闭,灯光1设置打开,喂鱼时,点击一键喂鱼按钮,系统将会把循环泵和%@进行关闭,灯光1打开,方便鱼儿进食10分钟后,喂鱼结束,系统会自动恢复喂鱼前的设备状态(如果关联的设备有定时,会按照定时执行)。",lightname,lightname,lightname]; CGSize size= [label.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:(NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: label.font} context:NULL].size; label.frame=CGRectMake((kScreenWidth-size.width)/2.0, CGRectGetMaxY(self.tableView.frame)+20, size.width, size.height); [self.view addSubview:label]; } -(void)clickCell:(TimerTypeTableViewCell *)cell button:(UIButton *)button timerType:(NSInteger )type { XuanduoTimerSettingViewController *_settingVC = [[XuanduoTimerSettingViewController alloc] init]; _settingVC.currentdevice = self.currentdevice; _settingVC.dataModel = self.dataModel; _settingVC.readMode=self.readMode; _settingVC.timerType=type; [self.navigationController pushViewController:_settingVC animated:YES]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2 + self.timeDic.allKeys.count+([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]?1:0); } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 0) { return 1; }else if (section == 1){ return 2; } if (section - 2 < _titieArr.count) { NSArray *dataArr = [self.timeDic objectForKey:_titieArr[section-2]]; return dataArr.count; } else { if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { return 1; } } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0){ TemperatureSetCell *cell = [tableView dequeueReusableCellWithIdentifier:temperatureCellid]; TemperatureSetModel *model=[[TemperatureSetModel alloc]init]; model.title = @"喂鱼设置"; cell.titleLabel.text = model.title; NSLog(@"wendu str = %@",_wenduString); model.temperatureLabel = _wenduString; 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.temPSwitch.hidden=YES; cell.icon.hidden=NO; cell.icon.image=[UIImage imageNamed:@"喂鱼"]; cell.titileLabelLayout.constant=40; cell.tempLabelLayout.constant=(kScreenWidth-38)/2.0-65-19; cell.temperaturelabel.textAlignment=NSTextAlignmentCenter; if (self.dataModel) { Xuanduo2Model*model=self.dataModel; if ([model.alarmSwitch isEqualToString:@"01"]) { [cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal]; cell.temPSwitch.selected = NO; }else{ [cell.temPSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal]; cell.temPSwitch.selected = YES; } } return cell; }else if(indexPath.section == 1 && indexPath.row == 0){ if (![self.currentdevice.waterRemind isEqual:[NSNull null]]) { ChangeWaterCell *cell = [tableView dequeueReusableCellWithIdentifier:changeWaterCellid]; [cell.ChangeWaterSwitch addTarget:self action:@selector(xuTochangeWaterSwitch:) forControlEvents:UIControlEventTouchUpInside]; if ([self.waterInfmodel.waterremind isEqualToString:@"1"]) { [cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"greenbtn_big"] forState:UIControlStateNormal]; cell.ChangeWaterSwitch.selected = NO; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"firstSetCell"]]; _huanShuiSwitchIsOn=YES; }else{ [cell.ChangeWaterSwitch setBackgroundImage:[UIImage imageNamed:@"graybtn_big"] forState:UIControlStateNormal]; cell.ChangeWaterSwitch.selected = YES; _huanShuiSwitchIsOn=NO; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"set_cellBack"]]; } if (self.waterInfmodel.remindcycle == 0) { //在未获取换水信息时暂时显示 cell.huanshuiDaylabel.text=@"换水时间"; if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { cell.huanshuiDaylabel.text=@"杀菌时间"; cell.titleLabel.text=@"杀菌提醒"; } }else{ cell.huanshuiDaylabel.text=[NSString stringWithFormat:@"%ld天",(long)self.waterInfmodel.remindcycle]; } return cell; } }else if (indexPath.section==1 && indexPath.row == 1){ static NSString*nextHuanShuiLablecellId=@"labelcell"; UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:nextHuanShuiLablecellId]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nextHuanShuiLablecellId]; } if (_huanShuiSwitchIsOn) { cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.waterInfmodel.remindDate]; if (!self.waterInfmodel.remindDate) { cell.textLabel.text=[NSString stringWithFormat:@"下次换水时间:%@",self.nextChangeDateLabel]; } if ([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { cell.textLabel.text=[NSString stringWithFormat:@"下次杀菌时间:%@",self.waterInfmodel.remindDate]; if (!self.waterInfmodel.remindDate) { cell.textLabel.text=[NSString stringWithFormat:@"下次杀菌时间:%@",self.nextChangeDateLabel]; } } cell.textLabel.font=[UIFont systemFontOfSize:15]; [cell.textLabel sizeToFit]; cell.textLabel.textColor =[UIColor colorWithRed:146.0/256.0 green:146.0/256.0 blue:146.0/256.0 alpha:1]; cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"secondSetCell"]]; } else{ cell.textLabel.text=@""; } cell.userInteractionEnabled = NO; return cell; }else if(indexPath.section -2== _titieArr.count && indexPath.row == 0&&[self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]){ TemperatureSetCell *cell = [tableView dequeueReusableCellWithIdentifier:temperatureCellid]; TemperatureSetModel *model=[[TemperatureSetModel alloc]init]; model.title = @"恒温设置"; cell.titleLabel.text = model.title; Xuanduo3fModel*xmodel=(Xuanduo3fModel*)_dataModel; NSString*heating = xmodel.heatingTemperature; UInt64 heat = [dataContorl hexToTen:heating]; float formatheat = heat/10; model.temperatureLabel = [NSString stringWithFormat:@"%f",formatheat]; cell.temPSwitch.hidden=YES; cell.temperaturelabel.frame=cell.temPSwitch.frame; Xuanduo3fModel*model3=self.dataModel; int mac=[dataContorl hexToTen:model3.heatingTemperature]; //float TPlabel=mac/10+(mac%10)*0.1; float temp = mac/10.0; NSString *stringTemp = [NSString stringWithFormat:@"%.1f℃",temp]; cell.temperaturelabel.textAlignment=NSTextAlignmentRight; [cell.temperaturelabel setAttributedText:[NSString ls_changeFontAndColor:[UIFont systemFontOfSize:15] Color:nil TotalString:stringTemp SubStringArray:@[@"℃"]]]; return cell; } else { if (indexPath.section - 2 < _titieArr.count && _selectSection == indexPath.section) { NSArray *dataArr = [self.timeDic objectForKey:_titieArr[indexPath.section-2]]; BOOL havePlus = [dataArr containsObject:plusflag]; if (havePlus && (indexPath.row == dataArr.count-1)) { TimerTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:timerTypeFlag]; if (!cell) { cell=[[TimerTypeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:timerTypeFlag]; } cell.delegate=self; return cell; }else { SetTimerCell *cell = [tableView dequeueReusableCellWithIdentifier:setTimerflag forIndexPath:indexPath]; cell.switchBtn.tag = kSwitchBtnTag + indexPath.row; [cell.switchBtn addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside]; XuanduoTimerGroup *group = [dataArr objectAtIndex:havePlus?indexPath.row+1:indexPath.row]; cell.model=group; if ([group isKindOfClass:[XuanduoTimerGroup class]]) { BOOL isOn = NO; if ([group.status isEqualToString:@"01"]) { isOn = YES; } [cell configTitleLabel:[NSString stringWithFormat:@"时段%@",group.groupNumber] timer:group.time switchStatus:isOn]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } else if([group isKindOfClass:[XuanduoCycleModel class]]) { XuanduoCycleModel*model=group; BOOL isOn = NO; if ([model.status isEqualToString:@"00"]) { isOn = YES; } [cell configTitleLabel:@"循环开关" timer:[NSString stringWithFormat:@"持续时长%d分钟",[dataContorl hexToTen:model.lastTime]] switchStatus:isOn]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } } } return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@""]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { return 50; }else if (indexPath.section == 1 && indexPath.row == 0){ return 0; }else if (indexPath.section == 1 && indexPath.row == 1){ if (!_huanShuiSwitchIsOn) { }else { return 0; } }else if (indexPath.section - 2 <_titieArr.count) { NSArray *dataArr = [self.timeDic objectForKey:_titieArr[indexPath.section-2]]; //不展开 BOOL havePlus = [dataArr containsObject:plusflag]; if (_selectSection == indexPath.section) { return 0; }else { return 0; } } else if(indexPath.section - 2 ==_titieArr.count&&[self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { return 50; } return 0; } #pragma mark tableView 头视图和脚视图 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0) { return 5; }else if (section == 2){ return 40; }else if (section == 3){ return 40; }else if (section == 4){ return 40; }else if (section == 5){ return [self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]?0:40; }else if (section == 6){ return 40; }else if (section == 7){ return 40; }else { return CGFLOAT_MIN; } } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section == 0) { UIView *oneHeader = [[UIView alloc] init]; oneHeader.backgroundColor = COLOR_MIAN; return oneHeader; }else if(section > 1){ XuanduoSelectHeader *headerView = [XuanduoSelectHeader shareHeaderView]; headerView.controlBtn.tag = kBtnTag + section; headerView.statusBtn.tag = kBtnTag + section; [headerView.controlBtn setImage:[UIImage imageNamed:@"normalImage"] forState:UIControlStateNormal]; [headerView.controlBtn setImage:[UIImage imageNamed:@"selectedImage"] forState:UIControlStateSelected]; [headerView.statusBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [headerView.statusBtn setTitleColor:[UIColor grayColor] forState:UIControlStateSelected]; [headerView.statusBtn setBackgroundColor:[UIColor whiteColor]]; headerView.statusBtn.hidden=NO; [headerView.controlBtn addTarget:self action:@selector(foldAction:) forControlEvents:UIControlEventTouchUpInside]; [headerView.statusBtn addTarget:self action:@selector(statusChangeAction:) forControlEvents:UIControlEventTouchUpInside]; NSInteger location=0; switch (section - 2) { case 0: //循环泵 { location = 3; } break; case 1: //增氧 { location = 0; } break; case 2: //灯光1 { location=1; } break; case 3: //灯光2 { location = 2; } break; case 4: //造浪泵 { location=5; } break; case 5: //杀菌灯 { location=4; } break; default: break; } NSString*choose=[dataContorl getBinaryByHex:self.fishFeedModel.lightChooseStatus location:location]; NSString*open=[dataContorl getBinaryByHex:self.fishFeedModel.lightOpenStatus location:location]; if ([open isEqualToString:@"1"]) { headerView.statusBtn.selected=YES; } else { headerView.statusBtn.selected=NO; } if ([choose isEqualToString:@"1"]) { headerView.controlBtn.selected=YES; } else { headerView.controlBtn.selected=NO; } [headerView configWithImageName:_imgArr[section-2] labelName:_titieArr[section-2]]; if (section==7) { headerView.backImageView.image=[UIImage imageNamed:@"bottomRound"]; } return headerView; } return nil; } #pragma mark tableView 点击事件 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ _indexPath = indexPath; if (indexPath.section==0&&indexPath.row==0){ //换水提醒日期选择 _remindPic=[[remindCyclePic alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height) type:@"feed"]; _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]; } } -(void)temperatureMainQueue{ NSArray*lowArr=[_mypicView.picArr objectAtIndex:0]; NSArray*heighArr=[_mypicView.picArr objectAtIndex:2]; for (NSInteger i=0; ilocation) { binaryLightChooseStatus =[binaryLightChooseStatus stringByReplacingCharactersInRange:NSMakeRange(location, 1) withString:btn.selected?@"1":@"0"]; } NSString*hexLightChooseStatus=[dataContorl getHexByBinary:binaryLightChooseStatus]; self.fishFeedModel.lightChooseStatus=hexLightChooseStatus; baseModel*readModel=[[baseModel alloc]init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId =self.currentdevice.macAddress; readModel.functionCode=@"15"; readModel.massagelegth=@"18"; NSString*readString=[NSString stringWithFormat:@"%@%@%@%@%@%@%@",readModel.description,@"09",self.fishFeedModel.feedTime,self.fishFeedModel.lightChooseStatus,self.fishFeedModel.lightOpenStatus,@"000000",@"0000"]; NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; [_indicatorView startAnimating]; [self readFishFeedModel]; } //改变一键喂鱼的开关状态 -(void)statusChangeAction:(UIButton*)btn { _selectSection = btn.tag - kBtnTag; btn.selected=!btn.selected; NSInteger section= _selectSection; NSInteger location=0; switch (section - 2) { case 0: //循环泵 { location = 3; } break; case 1: //增氧 { location = 0; } break; case 2: //灯光1 { location=1; } break; case 3: //灯光2 { location = 2; } break; case 4: //造浪泵 { location=5; } break; case 5: //杀菌灯 { location=4; } break; default: break; } NSString*binaryLightOpenStatus=[dataContorl getBinaryByHex:self.fishFeedModel.lightOpenStatus]; binaryLightOpenStatus =[binaryLightOpenStatus stringByReplacingCharactersInRange:NSMakeRange(location, 1) withString:btn.selected?@"1":@"0"]; NSString*hexBinaryLightOpenStatus=[dataContorl getHexByBinary:binaryLightOpenStatus]; self.fishFeedModel.lightOpenStatus=hexBinaryLightOpenStatus; baseModel*readModel=[[baseModel alloc]init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId =self.currentdevice.macAddress; readModel.functionCode=@"15"; readModel.massagelegth=@"18"; NSString*readString=[NSString stringWithFormat:@"%@%@%@%@%@%@%@",readModel.description,@"09",self.fishFeedModel.feedTime,self.fishFeedModel.lightChooseStatus,self.fishFeedModel.lightOpenStatus,@"000000",@"0000"]; NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; [_indicatorView startAnimating]; [self readFishFeedModel]; } - (void)switchAction:(UIButton *)btn { NSInteger index = btn.tag - kSwitchBtnTag; NSArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]]; BOOL havePlus = [dataArr containsObject:plusflag]; SetTimerModel *timerModel = [[SetTimerModel alloc] init]; timerModel.sendmacId =self.currentdevice.macAddress; timerModel.resavemacId = self.currentdevice.macAddress; timerModel.crc16str=@"0000"; XuanduoTimerGroup *group = [dataArr objectAtIndex:(havePlus?index+1:index)]; if ([group isKindOfClass: [XuanduoTimerGroup class] ]) { NSString*hexDateString1=[dataContorl dateStringToHexString:group.startTime]; NSString*hexDateString2=[dataContorl dateStringToHexString:group.endTime]; timerModel.selectorTime=[NSString stringWithFormat:@"%@%@",hexDateString1,hexDateString2]; timerModel.groupNumber = [dataContorl groupNumberTohex:group.groupNumber.integerValue]; if ([group.status isEqualToString:@"01"]) { timerModel.isOn = @"00"; }else { timerModel.isOn = @"01"; } ReadTimerModel *readModel = [[ReadTimerModel alloc] init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId = self.currentdevice.macAddress; readModel.crc16str=@"0000"; switch (_selectSection - 2) { case 0: //循环泵 { timerModel.selectorNumber = @"04"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"01"; } } break; case 1: //增氧 { timerModel.selectorNumber = @"01"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"02"; } } break; case 2: //灯光1 { timerModel.selectorNumber = @"02"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"03"; } } break; case 3: //灯光2 { timerModel.selectorNumber = @"03"; } break; case 4: //造浪泵 { timerModel.selectorNumber = @"06"; } break; case 5: //杀菌灯 { timerModel.selectorNumber = @"05"; } break; default: break; } NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str]; NSData*selctorData=[dataContorl stringToHexData:selectorString]; [[Socketsingleton sharedInstance] soketWriteData:selctorData]; // [_indicatorView startAnimating]; readModel.selectorNumber = timerModel.selectorNumber; NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str]; NSLog(@"read str = %@",readString); NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; ; } else if ([group isKindOfClass: [XuanduoCycleModel class] ]) { baseModel*tempModel=[[baseModel alloc]init]; tempModel.sendmacId =self.currentdevice.macAddress; tempModel.resavemacId =self.currentdevice.macAddress; tempModel.functionCode=@"18"; tempModel.massagelegth=@"17"; if ([_cycleModel.status isEqualToString:@"01"]) { _cycleModel.status = @"00"; }else { _cycleModel.status = @"01"; } NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@%@",tempModel.description,_cycleModel.lightNumber,_cycleModel.lastTime,_cycleModel.gapTime,_cycleModel.status,@"0000"]; NSData*tempData=[dataContorl stringToHexData:minString]; [[Socketsingleton sharedInstance] soketWriteData:tempData]; baseModel*readModel=[[baseModel alloc]init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId =self.currentdevice.macAddress; readModel.functionCode=@"19"; readModel.massagelegth=@"12"; NSString*readString=[NSString stringWithFormat:@"%@%@%@%@%@%@",readModel.description,_cycleModel.lightNumber,@"0000"]; NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; } } - (void)addTimer:(UIButton *)btn { _mydatepicView=[[MydatePickerView alloc]init]; _mydatepicView.pickerType = @"xuanduo"; _mydatepicView.frame=CGRectMake(0,0,kScreenSize.width,kScreenSize.height); [_mydatepicView.sureButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside]; [_mydatepicView.cancleButton addTarget:self action:@selector(deleteButtonClick) forControlEvents:UIControlEventTouchUpInside]; if (!btn) { _mydatepicView.haveDelected = YES; [self resetPickerView]; } // 设置pickerView 默认选择行 [self.view.window addSubview:_mydatepicView]; } - (void)resetPickerView { NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]]; BOOL havePlus = [dataArr containsObject:plusflag]; XuanduoTimerGroup *model = nil; if (havePlus) { model = dataArr[_indexPath.row + 1]; }else { model = dataArr[_indexPath.row]; } NSArray *startArr = [model.startTime componentsSeparatedByString:@":"]; NSArray *endArr = [model.endTime componentsSeparatedByString:@":"]; NSLog(@"stat %@ end %@",startArr,endArr); if (startArr.count == 2 && endArr.count == 2) { NSInteger row1 = [[_mydatepicView.dataArr objectAtIndex:0] indexOfObject:startArr[0]]; if (row1==NSNotFound) { row1=0; } [_mydatepicView.picView selectRow:row1 inComponent:0 animated:NO]; NSInteger row2 = [[_mydatepicView.dataArr objectAtIndex:1] indexOfObject:startArr[1]]; if (row2==NSNotFound) { row2=0; } [_mydatepicView.picView selectRow:row2 inComponent:1 animated:NO]; NSInteger row3 = [[_mydatepicView.dataArr objectAtIndex:2] indexOfObject:endArr[0]]; if (row3==NSNotFound) { row3=0; } [_mydatepicView.picView selectRow:row3 inComponent:2 animated:NO]; NSInteger row4 = [[_mydatepicView.dataArr objectAtIndex:3] indexOfObject:endArr[1]]; if (row4==NSNotFound) { row4=0; } [_mydatepicView.picView selectRow:row4 inComponent:3 animated:NO]; _mydatepicView.startString = startArr[0]; _mydatepicView.endString = startArr[1]; _mydatepicView.startString1 = endArr[0]; _mydatepicView.endString1 = endArr[1]; } } #pragma mark -- 设置时间段 -- -(void)doneButtonClick{ NSLog(@"点击了加号"); // 需要判断之前的时间段是否重叠 NSString *startTime = [NSString stringWithFormat:@"%@:%@",_mydatepicView.startString,_mydatepicView.endString]; NSString *endTime = [NSString stringWithFormat:@"%@:%@",_mydatepicView.startString1,_mydatepicView.endString1]; _mydatepicView.resultString=nil; if([startTime isEqualToString:endTime]){ [self showTitle:@"" messsage:@"开始时间不能等于结束时间"]; return; }else if (![self isValidTimer:startTime withEndTime:endTime] && !_mydatepicView.haveDelected){ [self showTitle:@"" messsage:@"添加的时间段与之前的重叠"]; return; }else{ _mydatepicView.resultString=[NSString stringWithFormat:@"%@~%@",startTime,endTime]; NSString*hexDateString1=[dataContorl dateStringToHexString:startTime]; NSString*hexDateString2=[dataContorl dateStringToHexString:endTime]; SetTimerModel *timerModel = [[SetTimerModel alloc] init]; timerModel.sendmacId =self.currentdevice.macAddress; timerModel.resavemacId = self.currentdevice.macAddress; timerModel.crc16str=@"0000"; timerModel.isOn = @"01"; timerModel.selectorTime=[NSString stringWithFormat:@"%@%@",hexDateString1,hexDateString2]; [_mydatepicView removeFromSuperview]; ReadTimerModel *readModel = [[ReadTimerModel alloc] init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId = self.currentdevice.macAddress; readModel.crc16str=@"0000"; NSInteger index = _selectSection - 2; if (index < _titieArr.count) { NSMutableArray *dataArr = [self.timeDic objectForKey:_titieArr[index]]; NSInteger groupNumber = 1; for (int i = 0 ; i < dataArr.count; i++) { if ([dataArr[i] isKindOfClass:[XuanduoTimerGroup class]] && ((XuanduoTimerGroup *)dataArr[i]).groupNumber.integerValue == groupNumber) { groupNumber++; } } NSLog(@"indexgroup = %d",groupNumber); timerModel.groupNumber = [dataContorl groupNumberTohex:groupNumber]; XuanduoTimerGroup *group; BOOL havePlus = NO; if (_mydatepicView.haveDelected) { havePlus = [dataArr containsObject:plusflag]; group = [dataArr objectAtIndex:havePlus?(_indexPath.row+1):_indexPath.row]; timerModel.groupNumber = [dataContorl groupNumberTohex:group.groupNumber.integerValue];; NSLog(@"realgroup = %ld",group.groupNumber.integerValue); timerModel.isOn = group.status; [dataArr removeObject:group]; if (![self isValidTimer:startTime withEndTime:endTime]) { [self showTitle:@"" messsage:@"添加的时间段与之前的重叠"]; [dataArr insertObject:group atIndex:havePlus?(_indexPath.row+1):_indexPath.row]; return; }else { [dataArr insertObject:group atIndex:havePlus?(_indexPath.row+1):_indexPath.row]; } } switch (index) { case 0: //循环泵 { timerModel.selectorNumber = @"04"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"01"; } } break; case 1: //增氧 { timerModel.selectorNumber = @"01"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"02"; } } break; case 2: //灯光1 { timerModel.selectorNumber = @"02"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"03"; } } break; case 3: //灯光2 { timerModel.selectorNumber = @"03"; } break; case 4: //造浪泵 { timerModel.selectorNumber = @"06"; } break; case 5: //杀菌灯 { timerModel.selectorNumber = @"05"; } break; default: break; } NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str]; NSData*selctorData=[dataContorl stringToHexData:selectorString]; [[Socketsingleton sharedInstance] soketWriteData:selctorData]; [_indicatorView startAnimating]; NSLog(@"hexString%@",selectorString); NSLog(@"result%@",_mydatepicView.resultString); readModel.selectorNumber = timerModel.selectorNumber; NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str]; NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; [_indicatorView startAnimating]; } } } /// 删除时间段 - (void)deleteButtonClick{ NSString*hexDateString1=[dataContorl dateStringToHexString:@"00:00"]; NSString*hexDateString2=[dataContorl dateStringToHexString:@"00:00"]; SetTimerModel *timerModel = [[SetTimerModel alloc] init]; timerModel.sendmacId =self.currentdevice.macAddress; timerModel.resavemacId = self.currentdevice.macAddress; timerModel.crc16str=@"0000"; timerModel.isOn = @"00"; timerModel.selectorTime=[NSString stringWithFormat:@"%@%@",hexDateString1,hexDateString2]; [_mydatepicView removeFromSuperview]; ReadTimerModel *readModel = [[ReadTimerModel alloc] init]; readModel.sendmacId =self.currentdevice.macAddress; readModel.resavemacId = self.currentdevice.macAddress; readModel.crc16str=@"0000"; NSInteger index = _selectSection - 2; NSLog(@"index = %d",index); if (index < _titieArr.count) { NSArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]]; BOOL havePlus = [dataArr containsObject:plusflag]; XuanduoTimerGroup *group = [dataArr objectAtIndex:(havePlus?_indexPath.row+1:_indexPath.row)]; timerModel.groupNumber = [dataContorl groupNumberTohex:group.groupNumber.integerValue]; switch (index) { case 0: //循环泵 { timerModel.selectorNumber = @"04"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"01"; } } break; case 1: //增氧 { timerModel.selectorNumber = @"01"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"02"; } } break; case 2: //灯光1 { timerModel.selectorNumber = @"02"; if([self.currentdevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) { timerModel.selectorNumber=@"03"; } } break; case 3: //灯光2 { timerModel.selectorNumber = @"03"; } break; case 4: //造浪泵 { timerModel.selectorNumber = @"06"; } break; case 5: //杀菌灯 { timerModel.selectorNumber = @"05"; } break; default: break; } NSString*selectorString=[NSString stringWithFormat:@"%@%@%@%@%@%@",timerModel.description,timerModel.selectorNumber,timerModel.groupNumber,timerModel.isOn,timerModel.selectorTime,timerModel.crc16str]; NSData*selctorData=[dataContorl stringToHexData:selectorString]; [[Socketsingleton sharedInstance] soketWriteData:selctorData]; [_indicatorView startAnimating]; NSLog(@"delete hexString = %@",selectorString); NSLog(@"result%@",_mydatepicView.resultString); readModel.selectorNumber = timerModel.selectorNumber; NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,readModel.selectorNumber,readModel.crc16str]; NSData*readData=[dataContorl stringToHexData:readString]; [[Socketsingleton sharedInstance] soketWriteData:readData]; [_indicatorView startAnimating]; } } /// 时间重叠则添加无效 - (BOOL)isValidTimer:(NSString *)startTime withEndTime:(NSString *)endTime{ __block BOOL isValid = YES; NSString *addEndtime = endTime; if ([startTime compare:endTime] == NSOrderedDescending) { //开始时间小于结束时间 跨天 NSInteger endHour = [addEndtime substringToIndex:2].integerValue; NSString *endHourStr = [NSString stringWithFormat:@"%ld",endHour + 24]; addEndtime = [NSString stringWithFormat:@"%@:%@",endHourStr,[addEndtime substringFromIndex:3]]; } NSArray *dataArr = [self.timeDic objectForKey:_titieArr[_selectSection-2]]; [dataArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[XuanduoTimerGroup class]]) { XuanduoTimerGroup *group = obj; NSString *compareEndTime = group.endTime; if (group.isCrossDay) { NSInteger hour = [compareEndTime substringToIndex:2].integerValue; NSString *hourStr = [NSString stringWithFormat:@"%ld",hour + 24]; compareEndTime = [NSString stringWithFormat:@"%@:%@",hourStr,[compareEndTime substringFromIndex:3]]; NSLog(@"跨天 compareendstr = %@",compareEndTime); if ([group.startTime compare:startTime] == NSOrderedSame && [compareEndTime compare:addEndtime] == NSOrderedSame) { isValid = NO; * stop = YES; NSLog(@"跨天1 compareendstr = %@",compareEndTime); }else if (([startTime compare:group.startTime] == NSOrderedAscending || [startTime compare:group.startTime] == NSOrderedSame)&& ([addEndtime compare:group.startTime] == NSOrderedDescending || [addEndtime compare:group.startTime] == NSOrderedSame)) { isValid = NO; * stop = YES; NSLog(@"跨天2 compareendstr = %@",compareEndTime); }else if (([startTime compare:group.startTime] == NSOrderedDescending || [startTime compare:group.startTime] == NSOrderedSame)&& ([addEndtime compare:compareEndTime] == NSOrderedAscending|| [addEndtime compare:compareEndTime] == NSOrderedSame)){ isValid = NO; * stop = YES; NSLog(@"跨天3 compareendstr = %@",compareEndTime); }else if ([startTime compare:group.endTime] == NSOrderedSame){ isValid = NO; * stop = YES; NSLog(@"跨天4 compareendstr = %@",compareEndTime); }else if (([startTime compare:group.startTime] == NSOrderedDescending || [startTime compare:group.startTime] == NSOrderedSame) && [startTime compare:compareEndTime] == NSOrderedAscending ){ isValid = NO; * stop = YES; } }else { NSLog(@"group.start=%@ group.end=%@ start=%@ end=%@",group.startTime,group.endTime,startTime,endTime); if ([group.startTime compare:startTime] == NSOrderedSame && [compareEndTime compare:addEndtime] == NSOrderedSame) { isValid = NO; * stop = YES; NSLog(@"不跨天1 compareendstr = %@",compareEndTime); }else if (([startTime compare:group.startTime] == NSOrderedAscending || [startTime compare:group.startTime] == NSOrderedSame)&& ([addEndtime compare:group.startTime] == NSOrderedDescending || [addEndtime compare:group.startTime] == NSOrderedSame)) { isValid = NO; * stop = YES; NSLog(@"不跨天2 compareendstr = %@",compareEndTime); }else if(([startTime compare:group.startTime] == NSOrderedDescending || [startTime compare:group.startTime] == NSOrderedSame)&& ([addEndtime compare:compareEndTime] == NSOrderedAscending|| [addEndtime compare:compareEndTime] == NSOrderedSame)){ isValid = NO; * stop = YES; NSLog(@"不跨天3 compareendstr = %@",compareEndTime); }else if ([startTime compare:group.endTime] == NSOrderedSame){ isValid = NO; * stop = YES; NSLog(@"不跨天4 compareendstr = %@",compareEndTime); }else if (([startTime compare:group.startTime] == NSOrderedDescending || [startTime compare:group.startTime] == NSOrderedSame) && [startTime compare:compareEndTime] == NSOrderedAscending ){ isValid = NO; * stop = YES; } } } }]; return isValid; } #pragma mark 温度设置 -(void)mypicViewRemoveByDone{ if (_mypicView.picViewResultString==nil) { [_mypicView removeFromSuperview]; }else{ if (_indexPath.section==0) { TemperatureSetCell*cell=[self.tableView cellForRowAtIndexPath:_indexPath]; cell.temperaturelabel.text=[NSString stringWithFormat:@"%@°C",_mypicView.picViewResultString]; } BackmassegeModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"DeviceBackInfo"]; // 低温 setWaringTpModel*warModel1=[[setWaringTpModel alloc]init]; warModel1.sendmacId =self.currentdevice.macAddress; warModel1.resavemacId =self.currentdevice.macAddress; warModel1.crc16Ing=@"0000"; warModel1.kaiguan=@"02";//设置 NSString*maxminTpString=warModel1.description; NSRange range=[_mypicView.picViewResultString rangeOfString:@"~"]; NSString*lowString=[_mypicView.picViewResultString substringToIndex:range.location]; int intlowString = [lowString intValue]; int newIntlowString=intlowString*10; warModel1.miniwaterTp=[dataContorl tpIntStringToFourHex:newIntlowString]; // 转四位16进制 //写入数据 backmodel.miniTp=warModel1.miniwaterTp; // 高温 setWaringTpModel*warModel2=[[setWaringTpModel alloc]init]; warModel2.sendmacId =self.currentdevice.macAddress; warModel2.resavemacId =self.currentdevice.macAddress; warModel2.crc16Ing=@"0000"; warModel2.kaiguan=@"02";//设置 NSString*heighString=[_mypicView.picViewResultString substringFromIndex:range.location+1]; int intString = [heighString intValue]; int newIntString=intString*10; warModel2.maxwaterTp=[dataContorl tpIntStringToFourHex:newIntString]; if ([lowString intValue]<[heighString intValue]) { backmodel.miniTp=warModel1.miniwaterTp; NSString*minString=[NSString stringWithFormat:@"%@%@%@%@%@",maxminTpString,warModel1.kaiguan,warModel1.miniwaterTp,warModel2.maxwaterTp,warModel1.crc16Ing]; NSLog(@"minstring = %@",minString); NSData*minwenDuData=[dataContorl stringToHexData:minString]; [[Socketsingleton sharedInstance] soketWriteData:minwenDuData]; backmodel.maxTp=warModel2.maxwaterTp; [_indicatorView startAnimating]; [_mypicView removeFromSuperview]; }else{ [self showTitle:@"提醒" messsage:@"请正确设置温度"]; } } } #pragma mark 默认换水时间 -(void)huanShuiMainQueue{ if ([_remindPic.type isEqualToString:@"feed"]) { int temp=[dataContorl hexToTen:self.fishFeedModel.feedTime]; if (temp<1) { temp=1; } [_remindPic.pic selectRow:temp-1 inComponent:0 animated:NO]; return; } else if ([_remindPic.type isEqualToString:@"cycle"]) { int mac=[dataContorl hexToTen:_cycleModel.lastTime]; //float TPlabel=mac/10+(mac%10)*0.1; NSInteger temp = mac; if (temp<1) { temp=1; } [_remindPic.pic selectRow:temp-1 inComponent:0 animated:NO]; return; } else if (_remindPic.picViewResultString !=nil || (_remindPic.picViewResultString ==nil && self.waterInfmodel.remindcycle !=0 )) { NSArray*shijianArr=[_remindPic.picArr objectAtIndex:0]; NSLog(@"a"); for (NSInteger k=0; k=0 && [readTimer isEqualToString:@"0119"]) { } if ([readTimer isEqualToString:@"0108"] || [readTimer isEqualToString:@"0105"]) { [Xuanduo2DataUtility readSocketDataWithBackMsgModel:self.dataModel addWithBackData:data type:self.currentdevice.type]; [self refreshWithData:self.dataModel]; } [self.XuTohud hidmyHud]; [self.indicatorView stopAnimating]; [self.tableView reloadData]; } -(void)ifishDeviceLogInFail{ } -(void)ifishDeviceLogInSuccees{ [self readFishFeedModel]; } -(void)readFishFeedModel { if (!self.fishFeedModel) { self.fishFeedModel=[[XuanduoFishFeedModel alloc]init]; } //读取一键喂鱼状态 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{ } @end