1255 lines
46 KiB
Objective-C
1255 lines
46 KiB
Objective-C
//
|
||
// Xuanduo2fController.m
|
||
// Ifish
|
||
//
|
||
// Created by Alex on 2019/4/13.
|
||
// Copyright © 2019 lianlian. All rights reserved.
|
||
//
|
||
|
||
#import "Xuanduo2fController.h"
|
||
#import "LXPopView.h"
|
||
#import "DXPopover.h"
|
||
#import "DeviceCameraModel.h"
|
||
#import "XuToControlNameViewController.h"
|
||
#import "IfishDataUnity.h"
|
||
#import "CreatErWeiMaController.h"
|
||
#import "SongBaoViewController.h"
|
||
#import "XuToControlName.h"
|
||
#import "UserExtendataArchaver.h"
|
||
#import "UIButton+WebCache.h"
|
||
#import "NSString+Add.h"
|
||
#import "XuanduoHuliModel.h"
|
||
#import "Xuanduo2DataUtility.h"
|
||
#import "HaveHotCoolWenDuPicview.h"
|
||
#import "Xuanduo2SettingController.h"
|
||
#import "RuSunLightOrder.h"
|
||
#import "JHRefreshAmazingAniView.h"
|
||
#import "JHRefresh.h"
|
||
#import "searchDeviceModel.h"
|
||
#import "PetStoresViewController.h"
|
||
#import "UIImage+WaterMark.h"
|
||
#import "XuanduoSettingController.h"
|
||
#import "XuanduoElectricityController.h"
|
||
#import "XuanduofishFeedViewController.h"
|
||
|
||
#define kBtnTag 100
|
||
|
||
@interface Xuanduo2fController ()<LxPopViewDelegate,IfishCommuniteDelegate,HaveHotCoolWenDuPicviewDelegate,UIScrollViewDelegate>
|
||
@property(nonatomic,strong) DXPopover *popover;
|
||
@property (weak, nonatomic) IBOutlet UIView *positionView;
|
||
@property (weak, nonatomic) IBOutlet UILabel *shajunLight;
|
||
@property (weak, nonatomic) IBOutlet UILabel *zengyangLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *light1Label;
|
||
@property (weak, nonatomic) IBOutlet UILabel *light2Label;
|
||
@property (weak, nonatomic) IBOutlet UILabel *zaolangLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *huliLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *xunhuanLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *jiareLabel;
|
||
@property (weak, nonatomic) IBOutlet UIButton *brandBtn;
|
||
@property (weak, nonatomic) IBOutlet UILabel *brandName;
|
||
@property (nonatomic ,strong) Xuanduo2Model* dataModel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *tempLabel;
|
||
@property (weak, nonatomic) IBOutlet UILabel *tipLabel;
|
||
@property (nonatomic, strong) NSTimer *switchTimer;
|
||
@property (weak, nonatomic) IBOutlet UIButton *uvLight;
|
||
@property (weak, nonatomic) IBOutlet UIButton *gasPumpLight;
|
||
@property (weak, nonatomic) IBOutlet UIButton *light1;
|
||
@property (weak, nonatomic) IBOutlet UIButton *light2;
|
||
@property (weak, nonatomic) IBOutlet UIButton *waveLight;
|
||
@property (weak, nonatomic) IBOutlet UIButton *huliLight;
|
||
@property (weak, nonatomic) IBOutlet UIButton *waterLight;
|
||
@property (weak, nonatomic) IBOutlet UIButton *heatLight;
|
||
@property(nonatomic,copy) UIActivityIndicatorView *indicatorView;
|
||
@property(nonatomic,strong) HaveHotCoolWenDuPicview *wenduPicview;
|
||
@property(nonatomic,strong) MyHud *XuTohud;
|
||
@property (weak, nonatomic) IBOutlet UILabel *offLineLabel;
|
||
|
||
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
|
||
@property(nonatomic)BOOL isRefeshing;
|
||
@property(nonatomic) BOOL isconnect;// socket 是否连接
|
||
@property (weak, nonatomic) IBOutlet UIView *contentView;
|
||
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
|
||
@property(nonatomic,strong) XuanduoCycleModel *cycleModel;
|
||
@property(nonatomic,assign) NSInteger heartCount;
|
||
|
||
@property (weak, nonatomic) IBOutlet UILabel *waterLever;
|
||
@property(nonatomic,strong)XuanduoFishFeedModel*fishFeedModel;
|
||
|
||
|
||
|
||
@end
|
||
|
||
@implementation Xuanduo2fController
|
||
|
||
- (void)viewWillAppear:(BOOL)animated {
|
||
[super viewWillAppear:animated];
|
||
[Socketsingleton sharedInstance].communiteDelegate = self;
|
||
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName :[UIColor blackColor]};
|
||
if ([[Socketsingleton sharedInstance].clientSocket isConnected]&&[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
|
||
[self readCycleWithNumber:@"03"];
|
||
self.heartCount=0;
|
||
|
||
|
||
}
|
||
}
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
[self setup];
|
||
[self connect];
|
||
[self networknotify];
|
||
|
||
// Do any additional setup after loading the view from its nib.
|
||
}
|
||
-(void)networknotify
|
||
{
|
||
AFNetworkReachabilityManager*networkManager=[AFNetworkReachabilityManager sharedManager];
|
||
[networkManager startMonitoring];
|
||
[networkManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||
if (![Socketsingleton sharedInstance].clientSocket.isConnected)
|
||
{
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
[self InitSocket];
|
||
}
|
||
|
||
}];
|
||
}
|
||
- (void)setup{
|
||
self.title = self.currentDevice.showName;
|
||
//右侧菜单
|
||
UIImage *MyEquipmentImage = [UIImage imageNamed:@"right"];
|
||
UIButton *rightPopButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
[rightPopButton setImage:MyEquipmentImage forState:UIControlStateNormal];
|
||
rightPopButton.frame=CGRectMake(kScreenWidth-60,0,60,44);
|
||
[rightPopButton setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
|
||
[rightPopButton addTarget:self action:@selector(presentPopView) forControlEvents:UIControlEventTouchUpInside];
|
||
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightPopButton];
|
||
self.navigationItem.rightBarButtonItem =rightItem;
|
||
//品牌展示
|
||
[_brandBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetLogUrl,self.currentDevice.logo]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"brandLogo_hold"]];
|
||
_brandName.text = self.currentDevice.brandName;
|
||
self.dataModel=nil;
|
||
[self initCHNames];
|
||
[Socketsingleton sharedInstance].communiteDelegate = self;
|
||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tempSwitch)];
|
||
// [self.tempLabel addGestureRecognizer:tap];
|
||
[self creatRefreshView];
|
||
|
||
//宠物笼设备
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
self.imageView.image=[UIImage imageNamed:@"pet"];
|
||
|
||
self.waterLightTop.constant=55;
|
||
//照明
|
||
[self.waterLight setBackgroundImage:[UIImage imageNamed:@"照明关"] forState:UIControlStateNormal];
|
||
[self.waterLight setBackgroundImage:[UIImage imageNamed:@"照明开"] forState:UIControlStateSelected];
|
||
// self.xunhuanLabel.text=@"照明";
|
||
|
||
//换气
|
||
[self.gasPumpLight setBackgroundImage:[UIImage imageNamed:@"换气关"] forState:UIControlStateNormal];
|
||
[self.gasPumpLight setBackgroundImage:[UIImage imageNamed:@"换气开"] forState:UIControlStateSelected];
|
||
// self.zengyangLabel.text=@"换气";
|
||
//杀菌
|
||
[self.light1 setBackgroundImage:[UIImage imageNamed:@"杀菌关"] forState:UIControlStateNormal];
|
||
[self.light1 setBackgroundImage:[UIImage imageNamed:@"杀菌开"] forState:UIControlStateSelected];
|
||
// self.light1Label.text=@"杀菌";
|
||
|
||
|
||
//恒温
|
||
[self.light2 setBackgroundImage:[UIImage imageNamed:@"恒温关"] forState:UIControlStateNormal];
|
||
[self.light2 setBackgroundImage:[UIImage imageNamed:@"恒温开"] forState:UIControlStateSelected];
|
||
// self.light2Label.text=@"恒温";
|
||
self.tipLabel.text=@"宠物笼温度";
|
||
|
||
self.controlBtn.hidden=NO;
|
||
self.cameraBtn.hidden=NO;
|
||
self.waveLight.hidden=YES;
|
||
self.zaolangLabel.hidden=YES;
|
||
self.uvLight.hidden=YES;
|
||
self.shajunLight.hidden=YES;
|
||
self.huliLight.hidden=YES;
|
||
self.huliLabel.hidden=YES;
|
||
self.heatLight.hidden=YES;
|
||
self.jiareLabel.hidden=YES;
|
||
self.heartCount=0;
|
||
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])
|
||
{
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F]) {
|
||
self.imageView.image=[UIImage imageNamed:@"seaxuanduo"];
|
||
}
|
||
|
||
self.controlBtn.hidden=NO;
|
||
self.cameraBtn.hidden=NO;
|
||
[self.controlBtn setTitle:@"一键喂鱼" forState:UIControlStateNormal];
|
||
[self.controlBtn setBackgroundImage:[CommonUtils createImageWithColor:[UIColor lightGrayColor]] forState:UIControlStateNormal];
|
||
[self.controlBtn setBackgroundImage:[CommonUtils createImageWithColor:[UIColor cyanColor]] forState:UIControlStateSelected];
|
||
[self.controlBtn setBackgroundImage:[CommonUtils createImageWithColor:[UIColor cyanColor]] forState:UIControlStateHighlighted];
|
||
[self.cameraBtn setTitle:@"功率" forState:UIControlStateNormal];
|
||
[self.cameraBtn setBackgroundImage:[CommonUtils createImageWithColor:[UIColor lightGrayColor]] forState:UIControlStateNormal];
|
||
[self.cameraBtn setBackgroundImage:[CommonUtils createImageWithColor:[UIColor cyanColor]] forState:UIControlStateHighlighted];
|
||
self.heartCount=0;
|
||
|
||
}
|
||
}
|
||
|
||
- (void)connect {
|
||
if ([self.currentDevice.isBlacklist isEqualToString:@"0"]) {
|
||
[self InitSocket];//允许请求数据
|
||
}
|
||
}
|
||
|
||
#pragma mark - 刷新
|
||
-(void)creatRefreshView{
|
||
self.scrollview.delegate = self;
|
||
__weak typeof (self)weakSelf=self;
|
||
[weakSelf.scrollview addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
|
||
if (weakSelf.isRefeshing) {
|
||
return ;
|
||
}
|
||
|
||
weakSelf.isRefeshing=YES;
|
||
if (weakSelf.isconnect) {
|
||
searchDeviceModel*xinxiModel=[[searchDeviceModel alloc]init];
|
||
xinxiModel.resavemacId = self.currentDevice.macAddress;
|
||
xinxiModel.sendmacId = self.currentDevice.macAddress;
|
||
|
||
NSString*requestStr=xinxiModel.description;
|
||
NSLog(@"REQUEST = %@",requestStr);
|
||
NSData*data1=[dataContorl stringToHexData:requestStr];
|
||
[[Socketsingleton sharedInstance].clientSocket writeData:data1 withTimeout:-1 tag:0];
|
||
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
|
||
|
||
}else{// socket中断
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
[weakSelf InitSocket];
|
||
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[weakSelf endRefreshing];
|
||
});
|
||
|
||
}
|
||
}];
|
||
}
|
||
|
||
-(void)endRefreshing{
|
||
if (self.isRefeshing) {
|
||
self.isRefeshing=NO;
|
||
[self.scrollview headerEndRefreshingWithResult:JHRefreshResultSuccess];
|
||
}
|
||
}
|
||
|
||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
|
||
CGFloat offset = scrollView.contentOffset.y;
|
||
if (offset >0) {
|
||
[self.scrollview setContentOffset:CGPointMake(0, 0)];
|
||
}
|
||
}
|
||
|
||
#pragma mark - 连接socket
|
||
-(void)InitSocket{
|
||
NSLog(@"******%d",[Socketsingleton sharedInstance].clientSocket.isConnected);
|
||
if (![Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
|
||
//[[Socketsingleton sharedInstance];
|
||
}
|
||
// 切换设备 先断开然后重连
|
||
[Socketsingleton sharedInstance].macAddress = self.currentDevice.macAddress;
|
||
[[Socketsingleton sharedInstance] socketConnectHost];
|
||
|
||
}
|
||
|
||
#pragma mark 通信监听communiteDelegate
|
||
|
||
//当已经和服务端断开连接后调用该代理方法
|
||
//断线重连功能需要在这里进行
|
||
|
||
-(void)ifishSocketDidDisconnect:(AsyncSocket *)sock{
|
||
_isconnect=NO;
|
||
[self endRefreshing];
|
||
}
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err{
|
||
// NSLog(@"soket错误断开");
|
||
// NSLog(@"存留数据%@",[sock unreadData]);
|
||
_offLineLabel.hidden = NO;
|
||
self.waterLever.hidden=YES;
|
||
}
|
||
|
||
-(BOOL)ifishSocketWillConnect:(AsyncSocket *)sock{
|
||
|
||
// NSLog(@"将要链接");
|
||
return YES;
|
||
|
||
}
|
||
|
||
#pragma mark 当已经与服务端建立连接后调用的代理方法
|
||
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock ifishSocketdidConnectToHost:(NSString *)host port:(UInt16)port{
|
||
//已建立连接 登陆指令同意在soket单例中
|
||
_isconnect=YES;
|
||
}
|
||
|
||
//发送完成处理
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag{
|
||
[self endRefreshing];
|
||
}
|
||
|
||
#pragma mark 登陆成功后收到服务端的回执之后,调用的代理方法
|
||
|
||
//父类里面不执行此方法 接收服务器返回信息 在子类中做处理
|
||
|
||
//communiteDelegate
|
||
|
||
-(void)socketDidGetBackmsgData:(NSData *)data onsoket:(AsyncSocket *)sock{
|
||
//[_HUD hide:YES];
|
||
[self.XuTohud hidmyHud];
|
||
[self endRefreshing];
|
||
|
||
|
||
NSString*string1=[dataContorl dataToHexString:data];
|
||
NSLog(@"return str == %@",string1);
|
||
NSString *readTimer = [string1 substringToIndex:4];
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if ([readTimer isEqualToString:@"0119"])
|
||
{
|
||
|
||
_cycleModel=[[XuanduoCycleModel alloc]init];
|
||
[Xuanduo2DataUtility readCycleSocketDataWithBackMsgModel:_cycleModel addWithBackStr:string1 type:self.currentDevice.type];
|
||
if (_cycleModel.lastTime.length)
|
||
{
|
||
UInt64 mac1=[dataContorl hexToTen:_cycleModel.lastTime];
|
||
|
||
//float TPlabel=mac/10+(mac%10)*0.1;
|
||
float temp1 = mac1;
|
||
NSString *stringTemp = [NSString stringWithFormat:@"%f℃",temp1];
|
||
UIImage*uvNomal=[UIImage imageNamed:@"杀菌关"];
|
||
//关闭时不显示时间
|
||
// uvNomal=[uvNomal imageWaterMarkWithString:stringTemp rect:CGRectMake(140, 60, 60, 60) attribute:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:30]}];
|
||
[self.light1 setImage:uvNomal forState:UIControlStateNormal];
|
||
|
||
UIImage*uvsel=[UIImage imageNamed:@"杀菌开"];
|
||
uvsel=[uvsel imageWaterMarkWithString:stringTemp rect:CGRectMake(140, 60, 60, 60) attribute:@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:30]}];
|
||
// [self.light1 setImage:uvsel forState:UIControlStateSelected];
|
||
|
||
}
|
||
}else 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, 2)];
|
||
fishFeedModel.lightOpenStatus=[string1 substringWithRange:NSMakeRange(36, 2)];
|
||
|
||
self.fishFeedModel=fishFeedModel;
|
||
|
||
NSString*tips=@"";
|
||
if ([self.fishFeedModel.lightChooseStatus isEqualToString:@"00"]&&[self.fishFeedModel.lightOpenStatus isEqualToString:@"00"])
|
||
{
|
||
tips=@"请先添加喂鱼设置";
|
||
}
|
||
else if ([self.dataModel.fishFeedStatus isEqualToString:@"00"])
|
||
{
|
||
tips=@"您确定要立即喂鱼吗?";
|
||
}
|
||
else if ([self.dataModel.fishFeedStatus isEqualToString:@"01"])
|
||
{
|
||
tips=@"您确定要立即关闭喂鱼功能吗?";
|
||
}
|
||
UIAlertController*alert=[UIAlertController alertControllerWithTitle:@"提示" message:tips preferredStyle:UIAlertControllerStyleAlert];
|
||
UIAlertAction*okaction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
if ([self.fishFeedModel.lightChooseStatus isEqualToString:@"00"]&&[self.fishFeedModel.lightOpenStatus isEqualToString:@"00"])
|
||
{
|
||
XuanduofishFeedViewController *_settingVC = [[XuanduofishFeedViewController alloc] init];
|
||
_settingVC.currentdevice = self.currentDevice;
|
||
_settingVC.dataModel = self.dataModel;
|
||
[self.navigationController pushViewController:_settingVC animated:YES];
|
||
}
|
||
else
|
||
{
|
||
[self changeFeedStatus];
|
||
}
|
||
}];
|
||
UIAlertAction*cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
|
||
|
||
}];
|
||
[alert addAction:okaction];
|
||
[alert addAction:cancelAction];
|
||
|
||
[self presentViewController:alert animated:YES completion:nil];
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
[Xuanduo2DataUtility readSocketDataWithBackMsgModel:self.dataModel addWithBackData:data type:self.currentDevice.type];
|
||
[self setTemperature];
|
||
if (self.dataModel)
|
||
{
|
||
self.heartCount++;
|
||
}
|
||
//
|
||
if (self.dataModel&&[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) {
|
||
|
||
|
||
Xuanduo3fModel*model=(Xuanduo3fModel*)_dataModel;
|
||
NSString *stateString1 = [model.uvLamp substringWithRange:NSMakeRange(2, 2)];
|
||
//关闭或者首次时杀菌取设置的值,之后才是心跳的
|
||
if ([stateString1 isEqualToString:@"00"])
|
||
{
|
||
if (_cycleModel.lastTime.length)
|
||
{
|
||
model.vuPHstatus=_cycleModel.lastTime;
|
||
|
||
}
|
||
else //未收到设置值不显示
|
||
{
|
||
model.vuPHstatus=@"0000";
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
if (self.dataModel) {
|
||
_offLineLabel.hidden = YES;
|
||
}else {
|
||
_offLineLabel.hidden = NO;
|
||
self.waterLever.hidden=YES;
|
||
}
|
||
[Xuanduo2DataUtility resetNewXuanduoButtonState:self.uvLight gasPumpLight:self.gasPumpLight light1:self.light1 light2:self.light2 waveLight:self.waveLight huliLight:self.huliLight waterLight:self.waterLight heatLight:self.heatLight withModel:self.dataModel type:self.currentDevice.type];
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]) {
|
||
|
||
if (self.dataModel.waterLevel.length&&([self.dataModel.waterLevel isEqualToString:@"01"]||[self.dataModel.waterLevel isEqualToString:@"02"]))
|
||
{
|
||
self.waterLever.text=@"水位报警";
|
||
self.waterLever.textColor=[UIColor redColor];
|
||
self.waterLever.hidden=NO;
|
||
|
||
}
|
||
else
|
||
{
|
||
self.waterLever.hidden=YES;
|
||
}
|
||
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])
|
||
{
|
||
[self.cameraBtn setTitle:[NSString stringWithFormat:@"%ldw",[dataContorl hexToTen:self.dataModel.powerRating]] forState:UIControlStateNormal];
|
||
if ([self.dataModel.fishFeedStatus isEqualToString:@"01"])
|
||
{
|
||
self.controlBtn.selected=YES;
|
||
|
||
}
|
||
else
|
||
{
|
||
self.controlBtn.selected=NO;
|
||
}
|
||
}
|
||
|
||
//杀菌灯的状态
|
||
|
||
|
||
}
|
||
|
||
-(void)readCycleWithNumber:(NSString*)num
|
||
{
|
||
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,num,@"0000"];
|
||
|
||
NSData*readData=[dataContorl stringToHexData:readString];
|
||
[[Socketsingleton sharedInstance] soketWriteData:readData];
|
||
|
||
}
|
||
|
||
-(void)ifishDeviceLogInFail{
|
||
|
||
}
|
||
|
||
-(void)ifishDeviceLogInSuccees{
|
||
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
[self readCycleWithNumber:@"03"];
|
||
self.heartCount=0;
|
||
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
-(void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket{
|
||
|
||
}
|
||
|
||
#pragma mark -- actions --
|
||
|
||
- (IBAction)cameraBtnClick:(id)sender {
|
||
//XuanduoElectricityController
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])//一键喂鱼
|
||
{
|
||
XuanduoElectricityController *_settingVC = [[XuanduoElectricityController alloc] init];
|
||
_settingVC.currentdevice = self.currentDevice;
|
||
_settingVC.dataModel = self.dataModel;
|
||
[self.navigationController pushViewController:_settingVC animated:YES];
|
||
}
|
||
else if([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
|
||
NSString*cameraId=nil;
|
||
|
||
for (DeviceCameraModel *model in guanxiiArr) {
|
||
|
||
if (model.deviceId == self.currentDevice.deviceId ) {
|
||
|
||
|
||
cameraId=model.cameraId;
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
if (cameraId)
|
||
{
|
||
IfishCameraModel *camera;
|
||
NSArray*array=[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"];
|
||
for (IfishCameraModel*model in array) {
|
||
|
||
if ([model.cameraId isEqualToString:cameraId])
|
||
{
|
||
camera=model;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (camera)
|
||
{
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
//进入摄像头页面
|
||
IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init];
|
||
p2pVC.contact = camera;
|
||
|
||
[self.navigationController pushViewController:p2pVC animated:YES];
|
||
}
|
||
else
|
||
{
|
||
[self.view makeToast:@"暂无关联的摄像头"];
|
||
}
|
||
}
|
||
else
|
||
{
|
||
[self.view makeToast:@"暂无关联的摄像头"];
|
||
}
|
||
}
|
||
|
||
}
|
||
- (IBAction)controlBtnClick:(UIButton*)sender {
|
||
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])//一键喂鱼
|
||
{
|
||
|
||
[self readFishFeedModel];//先读取
|
||
|
||
|
||
}
|
||
else if([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
|
||
FormatTankAddCamera*model=[[DataCenter defaultDtacenter] valueForKey:@"currentStore"];
|
||
|
||
if (model)
|
||
{
|
||
PetStoresViewController*store=[[PetStoresViewController alloc]init];
|
||
store.store=model;
|
||
;
|
||
self.hidesBottomBarWhenPushed = YES;
|
||
[self.navigationController pushViewController:store animated:YES];
|
||
|
||
}
|
||
}
|
||
}
|
||
//改变喂鱼状态
|
||
-(void)changeFeedStatus
|
||
{
|
||
baseModel*readModel=[[baseModel alloc]init];
|
||
readModel.sendmacId =self.currentDevice.macAddress;
|
||
readModel.resavemacId =self.currentDevice.macAddress;
|
||
readModel.functionCode=@"0c";
|
||
readModel.massagelegth=@"12";
|
||
|
||
NSString*readString=[NSString stringWithFormat:@"%@%@%@",readModel.description,[self.dataModel.fishFeedStatus isEqualToString:@"00"]?@"01":@"00",@"0000"];
|
||
|
||
NSData*readData=[dataContorl stringToHexData:readString];
|
||
[[Socketsingleton sharedInstance] soketWriteData:readData];
|
||
|
||
[_indicatorView startAnimating];
|
||
}
|
||
- (IBAction)btnActions:(UIButton *)btn {
|
||
if (self.dataModel.gasPump) {
|
||
|
||
}else{
|
||
[self showLableAction:@"设备已离线"];
|
||
}
|
||
XuToLightModel * lightModel= [[XuToLightModel alloc] init];
|
||
lightModel.sendmacId = self.currentDevice.macAddress;
|
||
lightModel.resavemacId = self.currentDevice.macAddress;
|
||
NSString*switchString1=lightModel.description;
|
||
if (btn.selected) {//开
|
||
lightModel.switchBtn = @"00";
|
||
}else {// 关
|
||
lightModel.switchBtn = @"01";
|
||
}
|
||
lightModel.crc16Str=@"0000";// CRC16验证码
|
||
switch (btn.tag) {
|
||
case kBtnTag: // 循环泵
|
||
{
|
||
if([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
[self changLightStatus:lightModel withLightNumber:@"01" dataStr:switchString1];
|
||
}
|
||
else{
|
||
if (btn.selected) {
|
||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认关闭循环泵?" preferredStyle:UIAlertControllerStyleAlert];
|
||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
|
||
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||
[self changLightStatus:lightModel withLightNumber:@"04" dataStr:switchString1];
|
||
}];
|
||
[alertController addAction:cancelAction];
|
||
[alertController addAction:sureAction];
|
||
[self.navigationController presentViewController:alertController animated:YES completion:nil];
|
||
}else {
|
||
[self changLightStatus:lightModel withLightNumber:@"04" dataStr:switchString1];
|
||
}
|
||
}
|
||
|
||
}
|
||
break;
|
||
case kBtnTag + 1: //增氧
|
||
{
|
||
NSString*light=@"01";
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
light=@"02";
|
||
}
|
||
[self changLightStatus:lightModel withLightNumber:light dataStr:switchString1];
|
||
}
|
||
break;
|
||
case kBtnTag + 2: //灯光1
|
||
{
|
||
NSString*light=@"02";
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
light=@"03";
|
||
}
|
||
[self changLightStatus:lightModel withLightNumber:light dataStr:switchString1];
|
||
}
|
||
break;
|
||
case kBtnTag + 3: //灯光2
|
||
{
|
||
NSString*light=@"03";
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
light=@"04";
|
||
}
|
||
[self changLightStatus:lightModel withLightNumber:light dataStr:switchString1];
|
||
|
||
}
|
||
break;
|
||
case kBtnTag + 4: //造浪泵
|
||
{
|
||
[self changLightStatus:lightModel withLightNumber:@"06" dataStr:switchString1];
|
||
}
|
||
break;
|
||
case kBtnTag + 5: //杀菌灯
|
||
{
|
||
[self changLightStatus:lightModel withLightNumber:@"05" dataStr:switchString1];
|
||
}
|
||
break;
|
||
case kBtnTag + 6: //护理灯 单独处理
|
||
{
|
||
XuanduoHuliModel *huliModel = [[XuanduoHuliModel alloc] init];
|
||
huliModel.sendmacId = self.currentDevice.macAddress;
|
||
huliModel.resavemacId = self.currentDevice.macAddress;
|
||
NSString *switchString = huliModel.description;
|
||
if (btn.selected) {//开
|
||
huliModel.switchBtn = @"00";
|
||
}else {// 关
|
||
huliModel.switchBtn = @"01";
|
||
}
|
||
huliModel.crc16Str=@"0000";// CRC16验证码
|
||
NSString *switchString2 = [NSString stringWithFormat:@"%@%@%@",switchString,huliModel.switchBtn,huliModel.crc16Str];
|
||
NSData *manulData=[dataContorl stringToHexData:switchString2];
|
||
[[Socketsingleton sharedInstance] soketWriteData:manulData];
|
||
if ([Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
//soket 未断开时显示
|
||
[self creatXuToindicaterView];
|
||
[self.XuTohud myhudstart];
|
||
}
|
||
}
|
||
break;
|
||
case kBtnTag + 7: //加热棒
|
||
{
|
||
if (self.dataModel.gasPump) {
|
||
_wenduPicview=[[HaveHotCoolWenDuPicview alloc] init];
|
||
_wenduPicview.frame=CGRectMake(0, 0, kScreenSize.width, kScreenSize.height);
|
||
[_wenduPicview.sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
||
[self.view.window addSubview:_wenduPicview];
|
||
_wenduPicview.wenDuPicviewDelegate = self;
|
||
NSString *stateStr =nil;
|
||
NSString*status;
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])
|
||
{
|
||
status=((Xuanduo2Model*)self.dataModel).status;
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
status=((Xuanduo3fModel*)self.dataModel).constTmep;
|
||
}
|
||
if ([status isKindOfClass:[NSNull class]]||!status ) {
|
||
|
||
status = @"0000";
|
||
}
|
||
|
||
stateStr = [status substringWithRange:NSMakeRange(2, 2)];
|
||
[_wenduPicview initCateBtnSate:stateStr];
|
||
|
||
[self heatAction];
|
||
|
||
}else{
|
||
|
||
[self showLableAction:@"设备已离线"];
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
-(void)readFishFeedModel
|
||
{
|
||
//读取一键喂鱼状态
|
||
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];
|
||
|
||
}
|
||
#pragma mark - 加热棒处理 -
|
||
- (void)sureBtnClick:(UIButton *)btn {
|
||
NSLog(@"%@******** _wenduPicview.picViewResultString",_wenduPicview.picViewResultString);
|
||
if (_wenduPicview.picViewResultString ==nil) {
|
||
|
||
[_wenduPicview removeFromSuperview];
|
||
|
||
}else{
|
||
|
||
JiaReWenDuModel *model=[[JiaReWenDuModel alloc] init];
|
||
model.resavemacId = self.currentDevice.macAddress;
|
||
model.sendmacId = self.currentDevice.macAddress;
|
||
int intlowString = [_wenduPicview.picViewResultString intValue];
|
||
int newIntlowString=intlowString*10;
|
||
|
||
NSLog(@"%d******** newIntlowString",newIntlowString);
|
||
// 转四位16进制
|
||
model.JiaReWenDu=[dataContorl tpIntStringToFourHex:newIntlowString];
|
||
model.crc16Code =@"0000";
|
||
|
||
NSString * hexstring=[NSString stringWithFormat:@"%@%@%@",model.description,model.JiaReWenDu,model.crc16Code];
|
||
NSData*data=[dataContorl stringToHexData:hexstring];
|
||
|
||
[ [Socketsingleton sharedInstance] soketWriteData:data];
|
||
}
|
||
|
||
[_wenduPicview removeFromSuperview];
|
||
|
||
}
|
||
|
||
- (void)heatAction
|
||
{
|
||
UInt64 mac=0;
|
||
NSLog(@"%llu",mac);
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]) {
|
||
Xuanduo2Model*model=(Xuanduo2Model*)self.dataModel;
|
||
mac=[dataContorl hexToTen:model.heatingTemperature];
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
Xuanduo3fModel*model=(Xuanduo3fModel*)self.dataModel;
|
||
mac=[dataContorl hexToTen:model.heatingTemperature];
|
||
}
|
||
NSLog(@"%llu",mac);
|
||
float TPlabel=mac/10;
|
||
int temp= (int)(TPlabel+0.5);
|
||
NSString *stringFloat = [NSString stringWithFormat:@"%d",temp];
|
||
NSLog(@"%@",stringFloat);
|
||
NSArray*wenDuArr=[_wenduPicview.picArr objectAtIndex:0];
|
||
|
||
for (NSInteger i=0; i<wenDuArr.count; i++) {
|
||
|
||
NSString*picString=wenDuArr[i];
|
||
|
||
if ([picString isEqualToString:stringFloat ] ) {
|
||
|
||
[_wenduPicview.pic selectRow:i inComponent:0 animated:NO];
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
#pragma mark - 制冷制热指令
|
||
-(void)didSelectCoolOrHeat:(NSString *)hotCool{
|
||
RuSunLightOrder*lightOrder=[[RuSunLightOrder alloc]init];
|
||
lightOrder.sendmacId = self.currentDevice.macAddress;
|
||
lightOrder.resavemacId = self.currentDevice.macAddress;
|
||
NSString*switchString1=lightOrder.description;
|
||
lightOrder.switchBtn = hotCool;
|
||
lightOrder.crc16Str=@"0000";
|
||
lightOrder.lightNumber=@"07";
|
||
|
||
NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString1,lightOrder.lightNumber,lightOrder.switchBtn,lightOrder.crc16Str];
|
||
NSData*manulData=[dataContorl stringToHexData:switchString2];
|
||
[ [Socketsingleton sharedInstance] soketWriteData:manulData];
|
||
if ([Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
//soket 未断开时显示
|
||
[self creatXuToindicaterView];
|
||
[self.XuTohud myhudstart];
|
||
}
|
||
}
|
||
|
||
#pragma mark - 灯的控制
|
||
|
||
- (void)changLightStatus:(XuToLightModel *)lightModel withLightNumber:(NSString *)number dataStr:(NSString *)switchString1 {
|
||
lightModel.lightNumber = number;
|
||
NSString *switchString2 = [NSString stringWithFormat:@"%@%@%@%@",switchString1,lightModel.lightNumber,lightModel.switchBtn,lightModel.crc16Str];
|
||
NSData *manulData=[dataContorl stringToHexData:switchString2];
|
||
[[Socketsingleton sharedInstance] soketWriteData:manulData];
|
||
if ([Socketsingleton sharedInstance].clientSocket.isConnected) {
|
||
//soket 未断开时显示
|
||
[self creatXuToindicaterView];
|
||
[self.XuTohud myhudstart];
|
||
}
|
||
}
|
||
|
||
- (IBAction)brandClick:(id)sender {
|
||
SongBaoViewController *brand = [[SongBaoViewController alloc]init];
|
||
brand.brandIntroduce = self.currentDevice.brandIntroduce;
|
||
[self.navigationController pushViewController:brand animated:YES];
|
||
self.navigationController.navigationBarHidden=NO;
|
||
}
|
||
|
||
- (void)tempSwitch {
|
||
if ([self.tipLabel.text isEqualToString:@"当月电量"]) {
|
||
|
||
}else {
|
||
self.tipLabel.text = @"当月电量";
|
||
UInt64 mac = 0;
|
||
NSLog(@"%llu",mac);
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]) {
|
||
Xuanduo2Model*model=(Xuanduo2Model*)self.dataModel;
|
||
mac=[dataContorl hexToTen:model.electricity];
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
}
|
||
NSString *stringTemp = [NSString stringWithFormat:@"%llukwh",mac/10.0];
|
||
[self.tempLabel setAttributedText:[NSString ls_changeFontAndColor:[UIFont systemFontOfSize:15] Color:nil TotalString:stringTemp SubStringArray:@[@"kwh"]]];
|
||
if (!_switchTimer) {
|
||
_switchTimer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(changeTemp) userInfo:nil repeats:YES];
|
||
[[NSRunLoop currentRunLoop] addTimer:_switchTimer forMode:NSRunLoopCommonModes];
|
||
}
|
||
}
|
||
}
|
||
|
||
- (void)changeTemp {
|
||
|
||
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]) {
|
||
self.tipLabel.text = @"鱼缸温度";
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
self.tipLabel.text = @"宠物笼温度";
|
||
}
|
||
[self setTemperature];
|
||
[_switchTimer invalidate];
|
||
_switchTimer = nil;
|
||
}
|
||
|
||
- (void)goBackAction{
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
[[IfishDataUnity shareDataInstance] setAppTabRoot];
|
||
}
|
||
|
||
- (void)presentPopView{
|
||
UIImage *image = [UIImage imageNamed:@"popover_background_image_notrangle"];
|
||
NSArray *titleImgs = nil;
|
||
|
||
NSArray *titles=nil;
|
||
LXPopView *pop=[[LXPopView alloc] init];
|
||
CGFloat popRowH=160*(image.size.height/image.size.width);
|
||
//主控
|
||
pop.frame = CGRectMake(0, 0, 160, 160*(image.size.height/image.size.width) + (popRowH -12)/2);
|
||
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"Ifish_share_device",@"ifishdropview_set_device"];
|
||
|
||
titles=@[@"修改名称",@"删除设备",@"分享设备",@"鱼缸设置"];
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) {
|
||
|
||
titles=@[@"修改名称",@"删除设备",@"分享设备",@"宠物笼设置"];
|
||
}
|
||
|
||
|
||
|
||
pop.delegate = self;
|
||
|
||
pop.backgroundImage =image
|
||
;
|
||
pop.titles = titles;
|
||
|
||
pop.titleImgs =titleImgs;
|
||
|
||
DXPopover *popover = [DXPopover popover];
|
||
|
||
self.popover = popover;
|
||
|
||
popover.arrowSize = CGSizeMake(0.0,0.0);
|
||
|
||
[popover showAtView:_positionView withContentView:pop];
|
||
NSLog(@"设备右侧pop");
|
||
|
||
}
|
||
|
||
-(void)creatXuToindicaterView{
|
||
|
||
self.XuTohud = [[MyHud alloc]init];
|
||
self.XuTohud.frame=CGRectMake(0, CGRectGetMaxY(_tempLabel.frame) + 4, kScreenSize.width,kScreenSize.height*2/3 );
|
||
self.XuTohud.hudActivityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
|
||
[self.XuTohud myhudtimeOut];
|
||
//self.XuTohud.backgroundColor=[UIColor redColor];
|
||
|
||
[self.view addSubview:self.XuTohud];
|
||
NSLog(@"**********绚多加载***********");
|
||
|
||
}
|
||
|
||
#pragma mark - PopViewDelagate
|
||
|
||
-(void)disSelectedPopViewIndex:(NSIndexPath *)Index{
|
||
|
||
[self.popover dismiss];
|
||
|
||
if (Index.row == 0) {
|
||
//修改名称
|
||
[self shezhiMingCheng];
|
||
|
||
|
||
}else if (Index.row == 1){
|
||
//删除设备
|
||
|
||
[self deletDevice];
|
||
|
||
}else if (Index.row == 2){
|
||
//分享设备
|
||
[self fenXiangSheBei];
|
||
}else if (Index.row == 3){
|
||
[self setting];
|
||
}
|
||
|
||
}
|
||
|
||
#pragma mark - 修改设备名
|
||
|
||
- (void)setTemperature {
|
||
|
||
UInt64 mac = 0;
|
||
NSLog(@"%llu",mac);
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]) {
|
||
Xuanduo2Model*model=(Xuanduo2Model*)self.dataModel;
|
||
mac=[dataContorl hexToTen:model.waterTemperature];
|
||
}
|
||
else if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
Xuanduo3fModel*model=(Xuanduo3fModel*)self.dataModel;
|
||
mac=[dataContorl hexToTen:model.temperature];
|
||
}
|
||
//float TPlabel=mac/10+(mac%10)*0.1;
|
||
float temp = mac/10.0;
|
||
NSString *stringTemp = [NSString stringWithFormat:@"%.1f℃",temp];
|
||
[self.tempLabel setAttributedText:[NSString ls_changeFontAndColor:[UIFont systemFontOfSize:15] Color:nil TotalString:stringTemp SubStringArray:@[@"℃"]]];
|
||
}
|
||
|
||
-(void)shezhiMingCheng{
|
||
XuToControlNameViewController *_changeNameVC = [[XuToControlNameViewController alloc] init];
|
||
_changeNameVC.isNewdevice = YES;
|
||
_changeNameVC.name = self.title;
|
||
_changeNameVC.device = self.currentDevice;
|
||
__weak typeof (self)wself = self;
|
||
_changeNameVC.NameWithBlock = ^(NSString *nameStr){
|
||
wself.title = nameStr;
|
||
[wself initCHNames];
|
||
};
|
||
[ wself.navigationController pushViewController: _changeNameVC animated:YES];
|
||
}
|
||
|
||
/// 各种控制旋钮标题显示
|
||
-(void)initCHNames{
|
||
|
||
XuToControlName *name = [UserExtendataArchaver currentNewXuToControlName:self.currentDevice.macAddress];
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
name=[UserExtendataArchaver currentPetsXuToControlName:self.currentDevice.macAddress];
|
||
}
|
||
self.shajunLight.text = name.shajunLight;
|
||
self.zengyangLabel.text = name.zengyangPump;
|
||
self.light1Label.text = name.light1;
|
||
self.light2Label.text = name.light2;
|
||
self.zaolangLabel.text = name.zaolangPump;
|
||
self.huliLabel.text = name.huLiDeng;
|
||
self.xunhuanLabel.text = name.xunhuanPump;
|
||
self.jiareLabel.text = name.jiaRe;
|
||
}
|
||
|
||
#pragma mark - 删除设备
|
||
|
||
-(void)deletDevice{
|
||
|
||
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"提示" message:@"确认删除设备?" preferredStyle:UIAlertControllerStyleAlert];
|
||
|
||
[self presentViewController:ac animated:YES completion:nil];
|
||
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
|
||
|
||
|
||
|
||
}]];
|
||
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
|
||
|
||
|
||
//先判断此设备是否有关联 摄像头
|
||
|
||
//DeviceModel*deviceModel=[_deviceArr objectAtIndex:indexpath.row];
|
||
//要删除的设设备id
|
||
|
||
//存在则 解除关系 删除对应的cameraId
|
||
NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
|
||
|
||
for (DeviceCameraModel *model in guanxiiArr) {
|
||
|
||
if (self.currentDevice.deviceId == model.deviceId ) {
|
||
|
||
|
||
[guanxiiArr removeObject:model];
|
||
//保存新关系数组
|
||
[[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[self deleteDeviceRequset];
|
||
|
||
|
||
}]];
|
||
|
||
}
|
||
|
||
-(void)deleteDeviceRequset{
|
||
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
||
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||
NSMutableDictionary * para = [NSMutableDictionary dictionary];
|
||
|
||
NSString *priId = self.currentDevice.deviceId;
|
||
;
|
||
NSString *userId = self.currentDevice.userId;
|
||
|
||
[para setValue:priId forKey:@"priId.deviceId"];
|
||
[para setValue:userId forKey:@"priId.userId"];
|
||
NSString*string=[NSString stringWithFormat:@"%@/api/user/deleteDeviceUser.do",JIEKOUPORT];
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F]) {
|
||
string=[NSString stringWithFormat:@"%@/api/user/deletePetDeviceUser.do",JIEKOUPORT];
|
||
[para removeAllObjects];
|
||
para[@"userId"]=userId;
|
||
para[@"deviceId"]=priId;
|
||
}
|
||
// __weak typeof (self)weakSelf=self;
|
||
[mannager POST:string parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||
if (responseObject) {
|
||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||
NSLog(@"result:%@",resultDic[@"result"]);
|
||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||
|
||
[self showTitle:@"" messsage:@"删除成功"];
|
||
//重置数据库
|
||
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
|
||
|
||
for (DeviceModel *model in deviceArry) {
|
||
|
||
if ([model.deviceId isEqual:self.currentDevice.deviceId]) {
|
||
|
||
[newArr removeObject:model];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[[DataCenter defaultDtacenter] setValue: newArr forKey:@"deviceInfo"];
|
||
|
||
if ([newArr count]==0) {
|
||
|
||
NSArray *cameraArr= [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"];
|
||
if ([cameraArr count]!=0) {
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
}else{
|
||
//两种设备都
|
||
[[Socketsingleton sharedInstance] cutOffSocket];
|
||
|
||
}
|
||
|
||
}
|
||
|
||
[[IfishDataUnity shareDataInstance] setAppTabRoot];
|
||
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||
|
||
[self showTitle:@"" messsage:@"删除失败"];
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
|
||
|
||
[self showTitle:@"" messsage:@"请求验证失败,请重新登陆"];
|
||
|
||
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
|
||
|
||
[self showTitle:@"" messsage:@"请求被舍弃,未执行"];
|
||
}
|
||
}
|
||
|
||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||
|
||
[self showTitle:@"" messsage:@"请求异常"];
|
||
}];
|
||
}
|
||
|
||
#pragma mark - 分享设备
|
||
|
||
-(void)fenXiangSheBei{
|
||
|
||
CreatErWeiMaController*vc=[[CreatErWeiMaController alloc]init];
|
||
vc.isNewdevice = YES;
|
||
vc.erdevicemodel=self.currentDevice;
|
||
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
|
||
}
|
||
|
||
#pragma mark -设置页面 -
|
||
- (void)setting {
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO5F])
|
||
{
|
||
XuanduoSettingController *_settingVC = [[XuanduoSettingController alloc] init];
|
||
_settingVC.currentdevice = self.currentDevice;
|
||
_settingVC.dataModel = self.dataModel;
|
||
[self.navigationController pushViewController:_settingVC animated:YES];
|
||
}
|
||
else if (self.dataModel.gasPump.length) {
|
||
XuanduoSettingController *_settingVC = [[XuanduoSettingController alloc] init];
|
||
_settingVC.currentdevice = self.currentDevice;
|
||
_settingVC.dataModel = self.dataModel;
|
||
[self.navigationController pushViewController:_settingVC animated:YES];
|
||
}else{
|
||
[self.indicatorView stopAnimating];
|
||
[self showLableAction:@"设备连接中,或离线"];
|
||
[self.XuTohud hidmyHud];
|
||
}
|
||
}
|
||
|
||
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
||
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
|
||
[alert show];
|
||
|
||
}
|
||
|
||
- (id)dataModel {
|
||
if (!_dataModel) {
|
||
_dataModel = nil;
|
||
|
||
if ([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO3F])
|
||
{
|
||
_dataModel=[[Xuanduo3fModel alloc]init];
|
||
}
|
||
else if([self.currentDevice.type isEqualToString:DECICE_TYPE_XUANDUO2F]) {
|
||
|
||
_dataModel=[[Xuanduo2Model alloc]init];
|
||
}
|
||
else
|
||
{
|
||
_dataModel=[[Xuanduo2Model alloc]init];
|
||
}
|
||
}
|
||
return _dataModel;
|
||
}
|
||
|
||
- (void)showLableAction:(NSString *)str{
|
||
UILabel *laberAction =[[UILabel alloc]init];
|
||
laberAction.frame =CGRectMake(0, 0 , 100, 50);
|
||
laberAction.center = [[UIApplication sharedApplication] delegate].window.center;
|
||
laberAction.clipsToBounds =YES;
|
||
laberAction.layer.cornerRadius =5;
|
||
laberAction.alpha =1;
|
||
laberAction.text =str;
|
||
laberAction.textAlignment =NSTextAlignmentCenter;
|
||
laberAction.backgroundColor =IndicatorBack_COLOR;
|
||
laberAction.font=[UIFont systemFontOfSize:12];
|
||
laberAction.textColor=[UIColor whiteColor];
|
||
|
||
[UIView animateWithDuration:2.0 animations:^{
|
||
laberAction.alpha =0;
|
||
}completion:^(BOOL finished) {
|
||
[laberAction removeFromSuperview];
|
||
}];
|
||
[self.view addSubview:laberAction];
|
||
}
|
||
|
||
- (void)dealloc {
|
||
|
||
}
|
||
|
||
|
||
@end
|