ThingsAddInitViewController.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // ThingsInitViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 3. 20..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "ThingsAddInitViewController.h"
  9. #import "CustomButton.h"
  10. #import "CustomLabel.h"
  11. #import "CustomImageView.h"
  12. @interface ThingsAddInitViewController (){
  13. NSTimer *_timer;
  14. NSInteger _elapsedSeconds;
  15. CommandModel *_startCommand;
  16. CommandModel *_stopCommand;
  17. }
  18. @end
  19. // 가스밸브 타이틀 : 가스 밸브 센서 초기화
  20. // 가스밸브 장치초기화 코멘트 : 밸브를 열림 상태에 두고 "위로" 버튼을 비프음이 날 때까지 5초 이상 누르세요.
  21. // 가스밸브 이미지 명 : img_things_product_addimg_01_smartgasvalve_wait
  22. // 도어센서 타이틀 : 도어 센서 초기화
  23. // 도어센서 장치초기화 코멘트 : 센서 아래 버튼을 1회 누른 후 LED가 깜빡임을 멈추면 1회 더 누르세요.
  24. // 도어센서 이미지 명 : img_things_product_addimg_02_mutisensor_door_wait
  25. // 스마트플러그 타이틀 : 스마트 플러그 초기화
  26. // 스마트플러그 장치초기화 코멘트 : 위에 버튼에 빨간 불이 깜빡일 때까지 5초 이상 누르세요.
  27. // 스마트플러그 이미지 명 : img_things_product_addimg_03_smartplug_wait
  28. @implementation ThingsAddInitViewController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self initUI];
  32. [self prepareViewDidLoad];
  33. }
  34. - (void)viewDidAppear:(BOOL)animated {
  35. [super viewDidAppear:animated];
  36. [UIView animateWithDuration:kfAnimationDur animations:^{
  37. _maskView.alpha = 0.7;
  38. } completion:^(BOOL finished) {
  39. // _constraintPopViewTop.constant = (IPHONE_HEIGHT - _popView.height) / 2;
  40. [UIView animateWithDuration:kfAnimationDur animations:^{
  41. [self.view layoutIfNeeded];
  42. }];
  43. }];
  44. }
  45. - (void)initUI {
  46. // [self initTableViewAsDefaultStyle:_tableView];
  47. [self startLoading:NO];
  48. }
  49. - (void)prepareViewDidLoad {
  50. // [self startLoading:NO];
  51. _imgThings.image = [_addDevice imgaeForAddDel];
  52. _lblTitle.text = [NSString stringWithFormat:@"%@ 초기화", _addDevice.prdName];
  53. }
  54. #pragma mark - Main Logic
  55. - (void)requestExcludeDevice:(BOOL)isStart {
  56. SocketRequestModel *request = [[SocketRequestModel alloc] initWithMsgType:MSG_TYPE_DEVICE_COMMAND];
  57. NSDictionary *param = @{@"device_id": [[JDFacade facade].loginUser getHomeHubID],
  58. @"command_type":isStart? CMD_TYPE_UNPAIRING_START:CMD_TYPE_UNPAIRING_STOP,
  59. @"cust_id": [[JDFacade facade].loginUser custId],
  60. @"ctrt_grp_id": [[JDFacade facade].loginUser ctrtGrpId]};
  61. [request setRequestMsg:param];
  62. [self sendDataToSocket:request modelClass:[CommandModel class]];
  63. }
  64. -(void)startLoading:(BOOL)isStart {
  65. _imgLoading.hidden = !isStart;
  66. if (isStart) {
  67. _elapsedSeconds = kMaxTimeOut;
  68. NSLog(@"ElapsedSecond : %zd", _elapsedSeconds);
  69. if (!_timer) {
  70. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateInclusionStatus) userInfo:nil repeats:YES];
  71. }
  72. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  73. if ([_imgLoading.layer animationForKey:@"SpinAnimation"] == nil) {
  74. CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  75. animation.fromValue = [NSNumber numberWithFloat:0.0f];
  76. animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
  77. animation.duration = 2.0f;
  78. animation.repeatCount = INFINITY;
  79. [_imgLoading.layer addAnimation:animation forKey:@"SpinAnimation"];
  80. }
  81. });
  82. }
  83. else {
  84. _elapsedSeconds = kMaxTimeOut;
  85. if (_timer) {
  86. [_timer invalidate];
  87. _timer = nil;
  88. }
  89. if ([_imgLoading.layer animationForKey:@"SpinAnimation"] != nil) {
  90. [_imgLoading.layer removeAnimationForKey:@"SpinAnimation"];
  91. }
  92. }
  93. }
  94. - (void)updateInclusionStatus {
  95. // dispatch_async(dispatch_get_main_queue(), ^(void) {
  96. //
  97. // _elapsedSeconds--;
  98. //
  99. // if (_elapsedSeconds == 0) {
  100. // [self finishDeviceDel:NO];
  101. // }
  102. // });
  103. }
  104. - (void)finishDeviceDel:(BOOL)isSuccess {
  105. [self startLoading:NO];
  106. [self requestExcludeDevice:NO];
  107. // Thi *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"ThingsGeneralDelCompleteViewController" storyboardName:@"Things"];
  108. // vc.add = _delDevice;
  109. // vc.isSuccess = isSuccess;
  110. // // vc.addableDevice = _addableDevice;
  111. //
  112. // [self showTransparencyModalView:vc];
  113. }
  114. - (IBAction)btnCancelTouched:(id)sender {
  115. }
  116. #pragma mark - SocketService
  117. - (void) socketDidReceiveMessage:(id)message result:(SocketModel *)result
  118. {
  119. NSLog(@"Result Info : %@", result);
  120. NSLog(@"Result Info : %@", message);
  121. // if (result.messageType) {
  122. // <#statements#>
  123. // }
  124. NSLog(@"Message Type : %@", result.messageType);
  125. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_DEVICE_COMMAND]) {
  126. CommandModel *response = (CommandModel *)message;
  127. if (result.isSuccess) {
  128. if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_UNPAIRING_START]) {
  129. _startCommand = response;
  130. }
  131. else if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_UNPAIRING_STOP]) {
  132. _stopCommand = response;
  133. }
  134. }
  135. else {
  136. [self finishDeviceDel:NO];
  137. }
  138. }
  139. }
  140. - (void) socketDidFailWithError:(NSError *)error {
  141. [[JDFacade facade] loadIndicator:NO allowUserInteraction:YES];
  142. }
  143. -(void) receiveSocketData:(NSNotification *)notification {
  144. SocketModel *result = [[SocketModel alloc] initWithDictionary:notification.object error:nil];
  145. CommandModel *response = [[CommandModel alloc] initWithDictionary:notification.object error:nil];
  146. NSLog(@"Result : %@", result);
  147. NSLog(@"Response : %@", response);
  148. if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_DEVICE_COMMAND_RES]) {
  149. NSLog(@"Response : %@", response);
  150. if (result.isSuccess) {
  151. if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_UNPAIRING_START]) {
  152. if ([response.commandId isEqualToString:_startCommand.commandId]) {
  153. [self startLoading:YES];
  154. }
  155. }
  156. else if ([response.commandType isEquestToIgnoreCase:CMD_TYPE_UNPAIRING_STOP]) {
  157. [self startLoading:NO];
  158. [self finishDeviceDel:YES];
  159. }
  160. }
  161. else {
  162. [self finishDeviceDel:NO];
  163. }
  164. }
  165. else if ([result.messageType isEquestToIgnoreCase:MSG_TYPE_NODE_DELETE_RES]) {
  166. [self finishDeviceDel:YES];
  167. }
  168. }
  169. - (void)didReceiveMemoryWarning {
  170. [super didReceiveMemoryWarning];
  171. }
  172. @end