ifish/Ifish/controllers/HotBar/IfishHotBarVc.m

645 lines
23 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// IfishHotBarVc.m
// Ifish
//
// Created by 罗艺 on 2018/8/22.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import "IfishHotBarVc.h"
#import "IFishHotBarCell.h"
#import "IfishHotBarVo.h"
#import "IFishWaterChangeView.h"
#import "UIView+GetView.h"
#import "IfishHistoryView.h"
#import "AFHttpTool.h"
#import "IfishHotBarVc.h"
#import "MJExtension.h"
#import "Socketsingleton.h"
#import "IfishHotBarPackegeVo.h"
#import "UIView+Toast.h"
#import "IfishHotBarModifyNameVc.h"
#import "searchDeviceModel.h"
#import "IfishHotBarHeader.h"
#import "IfishCameraModel.h"
#import "SVProgressHUD.h"
#define HOTBARCELL @"hotBarCell"
@interface IfishHotBarVc ()<UITableViewDelegate,UITableViewDataSource,ChangeWaterDelegate,IfishHistoryViewBottomBarDelete>
@property (strong, nonatomic) UITableView *mainTableView;
@property(nonatomic,strong)NSMutableArray*datas;
@property(nonatomic,strong)IFishWaterChangeView*changeWaterView;
@property(nonatomic,strong)IfishHistoryView*historyView;
@property(nonatomic,strong)IfishHotBarVo*vo;
@property(nonatomic,strong)IfishHotBarHeader*header;
@property(nonatomic,assign)NSInteger curDay;
Assign BOOL isInitHostoryView;
@end
@implementation IfishHotBarVc
-(IfishHotBarHeader *)header{
if(_header==nil){
_header=[IfishHotBarHeader getView];
_header.frame=CGRectMake(0, 0, SCREEN_WIDTH, 207);
_header.tag=100;
UIView*view=[[UIView alloc]initWithFrame:_header.frame];
[view addSubview:_header];
self.mainTableView.tableHeaderView=view;
}
return _header;
}
-(void)wenduRequest{// 查询设备状态信息
searchDeviceModel*xinxiModel=[[searchDeviceModel alloc]init];
xinxiModel.resavemacId = self.devicemodel.macAddress;
xinxiModel.sendmacId = self.devicemodel.macAddress;
NSString*requestStr=xinxiModel.description;
NSData*data1=[dataContorl stringToHexData:requestStr];
[[Socketsingleton sharedInstance].clientSocket writeData:data1 withTimeout:-1 tag:0];
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
[self getHotBarInfo];
}
-(IfishHistoryView *)historyView{
if (!_historyView) {
_historyView=InitObject(IfishHistoryView);
_historyView.myDeleget=self;
[self.view addSubview:_historyView];
[_historyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
return _historyView;
}
//获取历史流量数据
-(void)getHistoryDataRequest{
self.isInitHostoryView = YES;
NSDate *curDate = [NSDate dateWithTimeInterval:self.curDay*60*60*-24 sinceDate:[NSDate date]];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];//创建一个日期格式化器
dateFormatter.dateFormat=@"yyyy-MM-dd";//指定转date得日期格式化形式
NSLog(@"%@",[dateFormatter stringFromDate:curDate]);//2015-11-20 08:24:04
NSString*curDateStr=[dateFormatter stringFromDate:curDate];
// __block NSString*b_dateStr=curDateStr;
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
NSDictionary*para=@{@"heaterMacAddress":self.devicemodel.macAddress,@"date":curDateStr};//yyyy-mm-dd
self.historyView.curdateStr=curDateStr;
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:getHotBarHistory params:para success:^(id response) {
NSLog(@"-----------%@",response);
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString*result=dict[@"result"];
[SVProgressHUD dismiss];
if ([result integerValue]==100) {
IfishHotBarVo*vo= [IfishHotBarVo mj_objectWithKeyValues:dict[@"data"]];
if (vo.phs.count<1) {
[SVProgressHUD showInfoWithStatus:@"暂无数据"];
}else{
self.historyView.datas=vo.phs;
}
}else{
[SVProgressHUD showInfoWithStatus:@"暂无数据"];
}
} failure:^(NSError *err) {
[SVProgressHUD dismiss];
[SVProgressHUD showInfoWithStatus:@"网络在开小差,请稍后!"];
}];
}
-(void)clickBottomBarWithIdx:(NSInteger)idx{
if (idx==10) {
self.curDay++;
if (self.curDay>7) {
[SVProgressHUD showInfoWithStatus:@"只能查询前七天数据!"];
self.curDay=7;
return;
}
}else{
self.curDay--;
if(self.curDay<0){
[SVProgressHUD showInfoWithStatus:@"只能查询前七天数据!"];
self.curDay=0;
return;
}
}
[self getHistoryDataRequest];
}
#pragma mark----设置参数代理---
-(IFishWaterChangeView *)changeWaterView{
if(_changeWaterView==nil){
_changeWaterView=[[IFishWaterChangeView alloc]init];
[self.view addSubview:_changeWaterView];
[self.changeWaterView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
_changeWaterView.myDelegate=self;
}
_changeWaterView.hidden=NO;
return _changeWaterView;
}
//设置换水周期
-(void)didSelectRow1:(NSString *)v andRow2:(NSString *)v2{
v=[v stringByReplacingOccurrencesOfString:@"" withString:@""];
v2=[v2 stringByReplacingOccurrencesOfString:@":00" withString:@""];
NSString*str=[NSString stringWithFormat:@"换水周期 %@天 %@:00",v,v2];
if (v2.length==0) {
str=[NSString stringWithFormat:@"换水周期 %@天",v];
}
IfishHotBarVo*vo=self.datas[4];
vo.title=str;
if (!self.vo.heater) {
self.vo.heater = InitObject(IfishHeaterVo);
}
self.vo.heater.heaterCycle=v;
self.vo.heater.heaterReminderTime=v2;
[self setTeampleture];
[self.mainTableView reloadData];
}
//设置加热温度
-(void)didChangeTemperature:(NSString *)temp{
temp=[temp stringByReplacingOccurrencesOfString:@"°c" withString:@""];
IfishHotBarVo*vo=self.datas[0];
self.vo.heaterNum=[NSString stringWithFormat:@"%f",temp.floatValue];
vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]];
[self.mainTableView reloadData];
[self setHeatTeapWith:temp];
}
//设置预警温度
-(void)didSelectTeamptrue:(NSString *)up andDown:(NSString *)down andWarnCode:(NSString *)code{
up=[up stringByReplacingOccurrencesOfString:@"°c" withString:@""];
down=[down stringByReplacingOccurrencesOfString:@"°c" withString:@""];
self.vo.wornCode=code;
self.vo.upTeamp=up;
self.vo.downTeamp=down;
[self setTeampletureWithUp:self.vo.upTeamp andDown:self.vo.downTeamp andHnum:0 andWarmC:self.vo.wornCode];
}
-(NSMutableArray *)datas{
if (_datas==nil) {
_datas=[NSMutableArray array];
IfishHotBarVo*vo=[[IfishHotBarVo alloc]init];
vo.title=@"设置水温";
vo.iconUrl=@"温度图标";
vo.isShowArrow=YES;
vo.subTitle=@"";
[_datas addObject:vo];
//预警温度 add V5.0.0
IfishHotBarVo*vo1=[[IfishHotBarVo alloc]init];
vo1.title=@"预警温度 ";
vo1.iconUrl=@"容积图标";
vo1.isShowArrow=YES;
vo1.subTitle=@"";
[_datas addObject:vo1];
IfishHotBarVo*vo2=[[IfishHotBarVo alloc]init];
vo2.title=@"水泵流量";
vo2.iconUrl=@"流量标";
vo2.isShowArrow=NO;
vo2.subTitle=@"无水";
[_datas addObject:vo2];
IfishHotBarVo*vo3=[[IfishHotBarVo alloc]init];
vo3.title=@"历史趋势";
vo3.iconUrl=@"走势图标";
vo3.isShowArrow=YES;
vo3.subTitle=@"";
[_datas addObject:vo3];
IfishHotBarVo*vo4=[[IfishHotBarVo alloc]init];
vo4.title=@"换水周期 ";
vo4.iconUrl=@"换水图标";
vo4.isShowArrow=YES;
vo4.subTitle=@"";
[_datas addObject:vo4];
}
return _datas;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.isInitHostoryView = NO;
// Do any additional setup after loading the view from its nib.
self.mainTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
[self.mainTableView registerNib:[UINib nibWithNibName:@"IFishHotBarCell" bundle:nil] forCellReuseIdentifier:HOTBARCELL];
self.mainTableView.rowHeight=70;
self.mainTableView.dataSource=self;
self.mainTableView.delegate=self;
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self.mainTableView reloadData];
[self getHotBarInfo];
self.tableView=self.mainTableView;
[self creatRefreshView];
[self header];
//
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
back.frame = CGRectMake(0,0,48,44);
[back setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
// [_bakbutton setBackgroundImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
[back addTarget: self action: @selector(clickBack) forControlEvents: UIControlEventTouchUpInside];
back.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[back setContentEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)];
UIBarButtonItem * backItem=[[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem=backItem;
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ifishnav_dropview_list"] style:0 target:self action:@selector(clickMoreBtn)];
[self.view bringSubviewToFront:self.popView];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
self.title=self.devicemodel.showName;
}
-(void)clickMoreBtn{
[self presentPopView];
}
-(void)deleteDeviceRequset{
[super deleteDeviceRequset];
}
-(void)deleteDeviceRequsetSus{
[self deleteHotBarInfo];
}
-(void)clickBack{
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
-(void)shezhiMingCheng{
IfishHotBarModifyNameVc*mVc=[[IfishHotBarModifyNameVc alloc]init];
mVc.devicemodel=self.devicemodel;
[self.navigationController pushViewController:mVc animated:YES];
}
#pragma mark------请求服务器-------
//删除加热棒
-(void)deleteHotBarInfo{
NSDictionary*para=@{
@"heaterMacAddress":self.devicemodel.macAddress
};
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:DeleteHotBar params:para success:^(id response) {
NSLog(@"-----------%@",response);
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString*result=dict[@"result"];
if ([result integerValue]==100) {
// self.vo=[IfishHotBarVo mj_objectWithKeyValues:dict[@"data"]];
[self.view makeToast:@"删除成功"];
}else{
[self.view makeToast:@"删除失败"];
}
//发送删除消息
//重置数据库
NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry];
for (DeviceModel *model in deviceArry) {
if ([model.deviceId isEqual:self.devicemodel.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];
}
}
[self.navigationController popViewControllerAnimated:YES];
} failure:^(NSError *err) {
[self.view makeToast:@"删除失败"];
}];
}
-(void)getHotBarInfo{
NSDictionary*para=@{@"heaterMacAddress":self.devicemodel.macAddress};
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:GetHotBarInfo params:para success:^(id response) {
NSLog(@"-----------%@",response);
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString*result=dict[@"result"];
[SVProgressHUD dismiss];
if ([result integerValue]==100) {
self.vo=[IfishHotBarVo mj_objectWithKeyValues:dict[@"data"]];
if (self.vo.phs.count>0) {
NSDate *curDate = [NSDate dateWithTimeInterval:self.curDay*60*60*-24 sinceDate:[NSDate date]];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];//创建一个日期格式化器
dateFormatter.dateFormat=@"yyyy-MM-dd";//指定转date得日期格式化形式
NSLog(@"%@",[dateFormatter stringFromDate:curDate]);//2015-11-20 08:24:04
NSString*curDateStr=[dateFormatter stringFromDate:curDate];
self.historyView.curdateStr=curDateStr;
self.historyView.datas=self.vo.phs;
self.historyView.hidden=YES;
}
//去除鱼缸容积
IfishHotBarVo*vo1=self.datas[4];
if (self.vo.heater.heaterCycle.length) {
if (self.vo.heater.heaterReminderTime.length) {
vo1.title=[NSString stringWithFormat:@"换水周期 %@天 %@:00",self.vo.heater.heaterCycle,self.vo.heater.heaterReminderTime];
}else{
vo1.title=[NSString stringWithFormat:@"换水周期 %@天",self.vo.heater.heaterCycle];
}
}
[self.mainTableView reloadData];
}else{
[SVProgressHUD showInfoWithStatus:@"暂无数据"];
}
} failure:^(NSError *err) {
[SVProgressHUD dismiss];
[SVProgressHUD showInfoWithStatus:@"网络错误,请稍后"];
}];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.datas.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
IFishHotBarCell*cell=[tableView dequeueReusableCellWithIdentifier:HOTBARCELL];
cell.vo=self.datas[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==2){//水泵流量,点击无效果
}else if (indexPath.row==3) {//历史趋势
if (!self.isInitHostoryView) {
[self getHistoryDataRequest];
}
self.historyView.hidden=NO;
}else{
[self changeWaterView];
self.changeWaterView.hotVo=self.vo;
self.changeWaterView.viewType=indexPath.row;
}
}
#pragma mark----socket返回----
-(void)ifishDeviceLogInFail{
// self.mainTableView.userInteractionEnabled=NO;
}
-(void)socketDidGetBackmsgData:(NSData *)data onsoket:(AsyncSocket *)sock{
self.mainTableView.userInteractionEnabled=YES;
NSLog(@"TwoControlView收到服务器的回执--->%@",data);
NSLog(@"TwoControlView收到服务器的回执--->%@",[NSThread currentThread]);
NSString*string1=[dataContorl dataToHexString:data];
NSLog(@"TwoControlView收到服务器的回执--->%@",string1);
NSString*functionCode=[string1 substringWithRange:NSMakeRange(2, 2)];
if ([functionCode isEqualToString:@"08"]) {
[self updateUiWithInfo:string1];
}else if([functionCode isEqualToString:@"05"]){
// [self setHeatTeapWith:self.vo.heaterNum];
}else if([functionCode isEqualToString:@"0e"]){
[self setTeampletureWithUp:self.vo.upTeamp andDown:self.vo.downTeamp andHnum:0 andWarmC:self.vo.wornCode];
}else if([functionCode isEqualToString:@"06"]){
[self updateUiWithInfo:string1];
[self endRefreshing];
}
}
-(void)updateUiWithInfo:(NSString*)info{
NSString*templeture=[info substringWithRange:NSMakeRange(36, 4)];
UInt64 temp=[dataContorl hexToTen:templeture];
float tempFloat=temp*0.1;
self.header.degreeLable.text=[NSString stringWithFormat:@"%0.1f°c",tempFloat];
//流量 46
NSString*ph=[info substringWithRange:NSMakeRange(46, 4)];
UInt64 phV=[dataContorl hexToTen:ph];
IfishHotBarVo*vo2=self.datas[2];
// phV=0;
vo2.phv=phV;
//phV给499则为正常其余的都是无水-V5.0.0
if (phV==499) {
vo2.subTitle=@"正常";
}else{
vo2.subTitle=@"无水";
}
self.vo.heaterNum=[info substringWithRange:NSMakeRange(40, 4)];
UInt64 heaterNum= [dataContorl hexToTen:self.vo.heaterNum];
float num=heaterNum*1.0;
if (heaterNum>100) {
num=heaterNum*0.1;
}
self.vo.heaterNum=[NSString stringWithFormat:@"%f",num];
IfishHotBarVo*vo=self.datas[0];
vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]];
self.vo.wornCode=[info substringWithRange:NSMakeRange(44, 2)];
// self.vo.wornCode=[NSString stringWithFormat:@"%llu",[dataContorl hexToTen:self.vo.wornCode]];
self.vo.upTeamp=[info substringWithRange:NSMakeRange(54, 4)];
self.vo.upTeamp=[NSString stringWithFormat:@"%f",[dataContorl hexToTen:self.vo.upTeamp]*0.1];
self.vo.downTeamp=[info substringWithRange:NSMakeRange(50, 4)];
self.vo.downTeamp=[NSString stringWithFormat:@"%f",[dataContorl hexToTen:self.vo.downTeamp]*0.1];
[self.mainTableView reloadData];
}
#pragma mark----UDP-----
//
//数据包头(15字节) 1 "发送消息类型填充00回复类型填充01
//"
//1 功能码
//6 发送方MAC地址
//6 接收方MAC地址
//1 消息长度,包长度(15+*的长度)
//
//设置报警温度指令(22字节) 15 数据包头
//1 开启关闭报警00关01开
//2 最低报警温度关闭报警时传0
//2 最高报警温度关闭报警时传0
//2 CRC16校验码
//设置换水周期
-(void)setTeampleture{
if (!self.vo.heater.heaterCycle||!self.vo.heater.heaterReminderTime) {
return;
}
self.vo.heater.heaterCycle=[self.vo.heater.heaterCycle stringByReplacingOccurrencesOfString:@"" withString:@""];
self.vo.heater.heaterReminderTime=[self.vo.heater.heaterReminderTime stringByReplacingOccurrencesOfString:@":00" withString:@""];
NSString*longNum=@"";
NSString*heaterWidth=@"";
NSString*heaterHeight=@"";
NSString*heaterId=@"";
NSString*heaterVolume=@"";
if (self.vo.heater.heaterId) {
heaterId=self.vo.heater.heaterId;
}
if (self.vo.heater.heaterVolume) {
heaterVolume=self.vo.heater.heaterVolume;
}
NSDictionary*para=@{
@"heaterId":heaterId,
@"heaterMacAddress":self.devicemodel.macAddress,
@"heaterVolume":heaterVolume,
@"heaterLong":longNum,
@"heaterWidth":heaterWidth,
@"heaterHeight":heaterHeight,
@"heaterCycle":self.vo.heater.heaterCycle,
@"heaterReminderTime":self.vo.heater.heaterReminderTime
};
[AFHttpTool requestWihtMethod:RequestMethodTypePost url:SaveHotBarInfo params:para success:^(id response) {
NSLog(@"-----------%@",response);
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString*result=dict[@"result"];
if ([result integerValue]==100) {
// self.vo=[IfishHotBarVo mj_objectWithKeyValues:dict[@"data"]];
[self showLableAction:@"修改成功"];
}
} failure:^(NSError *err) {
}];
}
#pragma mark-----打开预警温度开关----
-(void)clickWormCode:(NSString *)code{
IfishHotBarPackegeVo*pvo=[[IfishHotBarPackegeVo alloc]init];
pvo.msgType=@"00";
pvo.funcCode=@"05";
pvo.sendAdr=self.devicemodel.macAddress;
pvo.reciceAdr=self.devicemodel.macAddress;
pvo.lenth=@"16";
pvo.warnCode=code;
pvo.downTeamptrue=@"0000";
pvo.upTeamptrue=@"0000";
pvo.crcCode=@"0000";
NSString*stateString=[pvo description];
NSData*selctorData=[dataContorl stringToHexData:stateString];
[[Socketsingleton sharedInstance].clientSocket writeData:selctorData withTimeout:-1 tag:0];
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
}
-(void)setTeampletureWithUp:(NSString*)up andDown:(NSString*)down andHnum:(NSString*)num andWarmC:(NSString*)code{
if(!up||!down){
// [self.view makeToast:@"请选择最高温度或最低温度"];
[self setHeatTeapWith:num];
return;
}
IfishHotBarPackegeVo*pvo=[[IfishHotBarPackegeVo alloc]init];
pvo.msgType=@"00";
pvo.funcCode=@"05";
pvo.sendAdr=self.devicemodel.macAddress;
pvo.reciceAdr=self.devicemodel.macAddress;
pvo.lenth=@"16";
pvo.warnCode=code;
if([code isEqualToString:@"00"]){
pvo.downTeamptrue=@"0000";
pvo.upTeamptrue=@"0000";
}else{
pvo.warnCode=@"02";
pvo.downTeamptrue=[dataContorl ToHex:down.longLongValue*10];
if (pvo.downTeamptrue.length<4) {
pvo.downTeamptrue=[dataContorl leftAddZero:4 andStr:pvo.downTeamptrue];
}
pvo.upTeamptrue=[dataContorl ToHex:up.longLongValue*10];
if (pvo.upTeamptrue.length<4) {
pvo.upTeamptrue=[dataContorl leftAddZero:4 andStr:pvo.upTeamptrue];
}
}
pvo.crcCode=@"0000";
NSString*stateString=[pvo description];
NSData*selctorData=[dataContorl stringToHexData:stateString];
self.vo.heaterNum=num;
[[Socketsingleton sharedInstance].clientSocket writeData:selctorData withTimeout:-1 tag:0];
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
[self showLableAction:@"发送成功"];
}
//"设置加热温度
//(19字节)" 15 数据包头
//2 加热温度如设置为27.1℃0x10F转成16进制则为0x10F
//2 CRC16校验码
-(void)setHeatTeapWith:(NSString*)num{
if(!num){
[self.view makeToast:@"请选择加热温度"];
return;
}
IfishPackageHeaderVo*header=[[IfishPackageHeaderVo alloc]init];
header.msgType=@"00";
header.funcCode=@"0e";
header.sendAdr=self.devicemodel.macAddress;
header.reciceAdr=self.devicemodel.macAddress;
header.lenth=@"13";
// NSString*str=[NSString stringWithFormat:@"%@0",num];
NSString*crc=@"0000";
num=[dataContorl ToHex:num.longLongValue*10];
if (num.length<4) {
num=[dataContorl leftAddZero:4 andStr:num];
}
NSString*stateString=[NSString stringWithFormat:@"%@%@%@",[header getHeader],num,crc];
NSData*selctorData=[dataContorl stringToHexData:stateString];
[[Socketsingleton sharedInstance].clientSocket writeData:selctorData withTimeout:-1 tag:0];
[[Socketsingleton sharedInstance].clientSocket readDataWithTimeout:-1 tag:0];
[self showLableAction:@"发送成功"];
}
@end