SensorlistVCViewController.mm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. //
  2. // SensorlistVCViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by Megatron on 2019/3/25.
  6. // Copyright © 2019 Megatron. All rights reserved.
  7. //
  8. #import "SensorlistVCViewController.h"
  9. #import "SensorListCell.h"
  10. #import <FunSDK/FunSDK.h>
  11. #import <Masonry/Masonry.h>
  12. #import "SensorDeviceModel.h"
  13. #import "SensorInfo.h"
  14. #import "XMLinkWallSwitchCell.h"
  15. #import "Header.h"
  16. static NSString *const kSensorListCell = @"kSensorListCell";
  17. static NSString *const kXMLinkWallSwitchCell = @"kXMLinkWallSwitchCell";
  18. @interface SensorlistVCViewController () <UITableViewDelegate,UITableViewDataSource>
  19. @property (nonatomic,assign) int msgHandle;
  20. @property (nonatomic,strong) NSMutableArray <SensorDeviceModel *>*dataSource;
  21. @property (nonatomic,strong) UITableView *tbList;
  22. @property (nonatomic,copy) NSString *curSceneID;
  23. @property (nonatomic,assign) int tempRow;
  24. @property (nonatomic,copy) NSString *tempName;
  25. @end
  26. @implementation SensorlistVCViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.view.backgroundColor = [UIColor whiteColor];
  30. self.automaticallyAdjustsScrollViewInsets = NO;
  31. self.navigationController.navigationBar.translucent = NO;
  32. self.edgesForExtendedLayout = UIRectEdgeNone;
  33. self.curSceneID = @"001";
  34. self.msgHandle = FUN_RegWnd((__bridge void*)self);
  35. [self configNav];
  36. [self configSubviews];
  37. [self myLayout];
  38. [self getSensorList];
  39. }
  40. #pragma mark - UIConfig
  41. - (void)configNav{
  42. self.edgesForExtendedLayout = UIRectEdgeBottom;
  43. self.navigationItem.title = TS("Sensor_Config");
  44. self.navigationController.navigationBar.titleTextAttributes=
  45. @{NSForegroundColorAttributeName:[UIColor whiteColor],
  46. NSFontAttributeName:[UIFont systemFontOfSize:17]};
  47. UIButton *btnLeft = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  48. [btnLeft setBackgroundImage:[UIImage imageNamed:@"new_back.png"] forState:UIControlStateNormal];
  49. [btnLeft addTarget:self action:@selector(btnNavLeftClicked) forControlEvents:UIControlEventTouchUpInside];
  50. UIBarButtonItem *btnNavLeft = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];
  51. self.navigationItem.leftBarButtonItem = btnNavLeft;
  52. UIButton *btnRight = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  53. [btnRight setBackgroundImage:[UIImage imageNamed:@"device_list_add"] forState:UIControlStateNormal];
  54. [btnRight addTarget:self action:@selector(btnNavRightClicked) forControlEvents:UIControlEventTouchUpInside];
  55. UIBarButtonItem *btnNavRight = [[UIBarButtonItem alloc] initWithCustomView:btnRight];
  56. self.navigationItem.rightBarButtonItem = btnNavRight;
  57. }
  58. - (void)configSubviews{
  59. [self.view addSubview:self.tbList];
  60. }
  61. - (void)myLayout{
  62. [self.tbList mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.edges.equalTo(self);
  64. }];
  65. }
  66. #pragma mark - EventAction
  67. - (void)btnNavLeftClicked{
  68. [self.navigationController popViewControllerAnimated:YES];
  69. }
  70. - (void)btnNavRightClicked{
  71. [self beginAddSensor];
  72. }
  73. - (void)longPressHappened:(UILongPressGestureRecognizer *)gesture{
  74. CGPoint point = [gesture locationInView:self.tbList];
  75. NSIndexPath *indexPath = [self.tbList indexPathForRowAtPoint:point];
  76. if (indexPath.row >= self.dataSource.count || !indexPath) {
  77. return;
  78. }
  79. self.tempRow = (int)indexPath.row;
  80. __weak typeof(self)weakSelf = self;
  81. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  82. UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:TS("Delete") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  83. NSDictionary *dicInfo = [weakSelf.dataSource objectAtIndex:self.tempRow].dicListInfo;
  84. [weakSelf beginDeleteSensor:[dicInfo objectForKey:@"DevID"]];
  85. }];
  86. UIAlertAction *changeNameAction = [UIAlertAction actionWithTitle:TS("Change_Name") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  87. [weakSelf showNameInputView];
  88. }];
  89. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:TS("Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  90. }];
  91. [alert addAction:deleteAction];
  92. [alert addAction:changeNameAction];
  93. [alert addAction:cancelAction];
  94. [self.navigationController presentViewController:alert animated:YES completion:nil];
  95. }
  96. - (void)showNameInputView{
  97. __weak typeof(self)weakSelf = self;
  98. UIAlertController *alert = [UIAlertController alertControllerWithTitle:TS("Change_Name") message:nil preferredStyle:UIAlertControllerStyleAlert];
  99. UIAlertAction *actionOK = [UIAlertAction actionWithTitle:TS("OK") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  100. NSString *name = alert.textFields[0].text;
  101. if (name.length <= 0) {
  102. name = alert.textFields[0].placeholder;
  103. }
  104. self.tempName = name;
  105. NSDictionary *dicInfo = [weakSelf.dataSource objectAtIndex:self.tempRow].dicListInfo;
  106. [weakSelf changeSensorName:name sensorID:[dicInfo objectForKey:@"DevID"]];
  107. }];
  108. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:TS("Cancel") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  109. }];
  110. [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  111. textField.placeholder = TS("Input_Name");
  112. }];
  113. [alert addAction:actionCancel];
  114. [alert addAction:actionOK];
  115. [self presentViewController:alert animated:YES completion:nil];
  116. }
  117. #pragma mark - Action
  118. #pragma mark GetList
  119. - (void)getSensorList{
  120. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  121. [SVProgressHUD showWithStatus:@"Getting sensor list...."];
  122. //请求传感器列表
  123. char cfg[1024];
  124. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"GetAllDevList\", \"Arg1\" : \"\", \"Arg2\" : \"\"} }");
  125. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "GetAllDevList", 0, \
  126. 20000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  127. }
  128. #pragma mark BeginAdd
  129. - (void)beginAddSensor{
  130. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  131. [SVProgressHUD showWithStatus:@"Adding sensor...."];
  132. //开始配对
  133. char cfg[1024];
  134. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"StartAddDev\", \"Arg1\" : \"60000\", \"Arg2\" : \"\"} }");
  135. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "StartAddDev", 4096, \
  136. 60000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  137. }
  138. - (void)stopAddSensor{
  139. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  140. [SVProgressHUD showWithStatus:@"Stop Add sensor...."];
  141. char cfg[] = "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"StopAddDev\", \"Arg1\" : \"\", \"Arg2\" : \"\"} }";
  142. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "StopAddDev", 4096, \
  143. 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  144. }
  145. - (void)beginDeleteSensor:(NSString *)devID{
  146. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  147. [SVProgressHUD showWithStatus:@"Deleting sensor...."];
  148. char cfg[1024];
  149. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"DeleteDev\", \"Arg1\" : \"%s\", \"Arg2\" : \"\"} }", [devID UTF8String]);
  150. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "DeleteDev", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  151. }
  152. #pragma mark ChangeName
  153. - (void)changeSensorName:(NSString *)name sensorID:(NSString *)devID{
  154. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  155. [SVProgressHUD showWithStatus:@"Changing sensor name...."];
  156. char cfg[1024];
  157. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"ChangeDevName\", \"Arg1\" : \"%s\", \"Arg2\" : \"%s\"} }", [devID UTF8String], [name UTF8String]);
  158. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "ChangeDevName", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  159. }
  160. #pragma mark ChangeStatue
  161. - (void)beginChangeStatueOpen:(BOOL)ifOpen devID:(NSString *)devID{
  162. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  163. [SVProgressHUD showWithStatus:@"Changing sensor statue...."];
  164. char cfg[1024];
  165. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"ChangeDevStatus\", \"Arg1\" : \"%s\", \"Arg2\" : {\"sceneId\":\"%s\", \"status\":%d}} }", [devID UTF8String], [devID UTF8String], ifOpen ? 1 : 0);
  166. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "ChangeDevStatus", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  167. }
  168. #pragma mark GetSceneMode
  169. - (void)beginGetSceneMode{
  170. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  171. [SVProgressHUD showWithStatus:@"Getting sensor mode...."];
  172. char cfg3[1024];
  173. sprintf(cfg3, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"GetModeConfig\", \"Arg1\" : \"\", \"Arg2\" : \"\"} }");
  174. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "GetModeConfig", 0, \
  175. 20000, (char *)cfg3, (int)strlen(cfg3) + 1, -1, 0);
  176. }
  177. #pragma mark ChangeSceneMode
  178. - (void)beginChangeMode:(NSString *)modeID{
  179. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  180. [SVProgressHUD showWithStatus:@"Changing sensor mode...."];
  181. char cfg[1024];
  182. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"ChangeMode\", \"Arg1\" : \"%s\", \"Arg2\" : \"\"} }", [modeID UTF8String]);
  183. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "ChangeMode", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  184. }
  185. #pragma mark GetSensorOnlineState
  186. - (void)requestSensorState:(NSString *)sensorID{
  187. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  188. char cfg[1024];
  189. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"GetLinkState\", \"Arg1\" : \"%s\", \"Arg2\" : \"%s\"} }", [channel.deviceMac UTF8String], [sensorID UTF8String]);
  190. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "GetLinkState", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, 0);
  191. }
  192. - (void)requestSensorDetailStatus:(NSString *)sensorID{
  193. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  194. //请求设备信息
  195. char cfg2[1024];
  196. sprintf(cfg2, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"InquiryStatus\", \"Arg1\" : \"%s\", \"Arg2\" : \"\"} }", [sensorID UTF8String]);
  197. FUN_DevCmdGeneral(self.msgHandle, [channel.deviceMac UTF8String], 2046, "InquiryStatus", 4096, 5000, (char *)cfg2, (int)strlen(cfg2) + 1, -1, 0);
  198. }
  199. #pragma mark - Delegate
  200. #pragma mark UITableViewDataSource
  201. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  202. return 55;
  203. }
  204. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  205. return self.dataSource.count;
  206. }
  207. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  208. SensorDeviceModel *model = [self.dataSource objectAtIndex:indexPath.row];
  209. if ([[model.dicListInfo objectForKey:@"DevType"] intValue] == DEV_TYPE_WALLSWITCH) {
  210. XMLinkWallSwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:kXMLinkWallSwitchCell];
  211. [cell configureCellWithModel:[self.dataSource objectAtIndex:indexPath.row]];
  212. __weak typeof(self) weakSelf = self;
  213. cell.WallSwitchClickedAction = ^(NSInteger index, BOOL selected) {
  214. int controlMask = 0;
  215. int ignoreMask = 0;
  216. if (selected) {
  217. if (index == 1) {
  218. ignoreMask = ignoreMask | 6;
  219. controlMask = controlMask | 1;
  220. }
  221. else if (index == 2){
  222. ignoreMask = ignoreMask | 5;
  223. controlMask = controlMask | 2;
  224. }
  225. else{
  226. ignoreMask = ignoreMask | 3;
  227. controlMask = controlMask | 4;
  228. }
  229. }
  230. else{
  231. if (index == 1) {
  232. ignoreMask = ignoreMask | 6;
  233. }
  234. else if (index == 2){
  235. ignoreMask = ignoreMask | 5;
  236. }
  237. else{
  238. ignoreMask = ignoreMask | 3;
  239. }
  240. }
  241. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  242. char cfg[1024];
  243. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"ChangeSwitchState\", \"Arg1\" : \"%s\", \"SensorState\" : {\"ControlMask\":%d,\"IgnoreMask\":%d}} }", [[model.dicListInfo objectForKey:@"DevID"] UTF8String], controlMask,ignoreMask);
  244. FUN_DevCmdGeneral(weakSelf.msgHandle, [channel.deviceMac UTF8String], 2046, "ChangeSwitchState", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, (int)indexPath.row);
  245. };
  246. return cell;
  247. }else{
  248. SensorListCell *cell = [tableView dequeueReusableCellWithIdentifier:kSensorListCell];
  249. cell.indexRow = indexPath.row;
  250. [cell listenStatue:^(int statue, int indexRow) {
  251. __weak typeof(self)weakSelf = self;
  252. NSDictionary *info = [self.dataSource objectAtIndex:indexRow].dicListInfo;
  253. if ([[info objectForKey:@"DevType"] intValue] == DEV_TYPE_SOCKET) {
  254. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  255. char cfg[1024];
  256. sprintf(cfg, "{ \"Name\" : \"OPConsumerProCmd\", \"SessionID\" : \"0x00000002\", \"OPConsumerProCmd\" : {\"Cmd\" : \"ChangeSocketState\", \"Arg1\" : \"%s\", \"SensorState\" : {\"Command\":%d}} }", [[model.dicListInfo objectForKey:@"DevID"] UTF8String], statue);
  257. FUN_DevCmdGeneral(weakSelf.msgHandle, [channel.deviceMac UTF8String], 2046, "ChangeSocketState", 4096, 5000, (char *)cfg, (int)strlen(cfg) + 1, -1, (int)indexPath.row);
  258. }else{
  259. [weakSelf beginChangeStatueOpen:statue devID:[info objectForKey:@"DevID"]];
  260. }
  261. }];
  262. cell.lbTitle.text = [NSString stringWithFormat:@"Name:%@Type:%i",[model.dicListInfo objectForKey:@"DevName"],[[model.dicListInfo objectForKey:@"DevType"] intValue]];
  263. if ([[model.dicListInfo objectForKey:@"DevType"] intValue] == DEV_TYPE_SOCKET) {
  264. int status = [[model.dicStatusInfo objectForKey:@"DevStatus"] intValue];
  265. cell.statueSwitch.on = status == 1 ? YES : NO;
  266. }else{
  267. cell.statueSwitch.on = [[model.dicListInfo objectForKey:@"Status"] boolValue];
  268. }
  269. return cell;
  270. }
  271. }
  272. #pragma mark - FunSDK Result
  273. -(void)OnFunSDKResult:(NSNumber *)pParam {
  274. NSInteger nAddr = [pParam integerValue];
  275. MsgContent *msg = (MsgContent *)nAddr;
  276. switch (msg->id) {
  277. case EMSG_DEV_CMD_EN:
  278. {
  279. if (msg->param1 < 0) {
  280. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%l",msg->param1]];
  281. } else{
  282. if (msg->param3 == 2046) {
  283. [SVProgressHUD dismiss];
  284. NSString *cmdName = [NSString stringWithUTF8String:msg->szStr];
  285. NSData *retJsonData = [NSData dataWithBytes:msg->pObject length:strlen(msg->pObject)];
  286. NSError *error;
  287. NSDictionary *retDic = [NSJSONSerialization JSONObjectWithData:retJsonData options:NSJSONReadingMutableLeaves error:&error];
  288. if (!retDic) {
  289. return;
  290. }
  291. int ret = [retDic[@"Ret"] intValue];
  292. if (ret != 100) {
  293. [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"ret%i",ret]];
  294. } else {
  295. if ([cmdName isEqualToString:@"StartAddDev"]) {
  296. NSDictionary *startAddDevDic = retDic[@"StartAddDev"];
  297. if (startAddDevDic) {
  298. [SVProgressHUD showSuccessWithStatus:@"Add Success"];
  299. // startAddDevDic contains sensor device info
  300. // key @"DevID" use this to modify sensor info like change DevName or Status
  301. // key @"DevName"
  302. // key @"DevType" distinguish device type just like gass or smoke sensor ,they have different DevType
  303. // key @"Status" this value meas alarm message will send to camera .Only keep it open (Status = 1) ,you can get push message.
  304. SensorDeviceModel *device = [[SensorDeviceModel alloc] init];
  305. device.dicListInfo = [startAddDevDic mutableCopy];
  306. [self.dataSource addObject:device];
  307. [self.tbList reloadData];
  308. }
  309. }else if ([cmdName isEqualToString:@"ChangeDevName"]){
  310. NSMutableDictionary *dicChange = [[self.dataSource objectAtIndex:self.tempRow] mutableCopy];
  311. [dicChange setObject:self.tempName forKey:@"DevName"];
  312. //[self.dataSource replaceObjectAtIndex:self.tempRow withObject:dicChange];
  313. [self.tbList reloadData];
  314. }else if ([cmdName isEqualToString:@"GetAllDevList"]){
  315. NSArray *arr = [retDic objectForKey:@"GetAllDevList"];
  316. if (arr && ![[NSNull null] isEqual:arr]) {
  317. [self.dataSource removeAllObjects];
  318. for (int i = 0; i < arr.count; i ++) {
  319. SensorDeviceModel *device = [[SensorDeviceModel alloc] init];
  320. device.dicListInfo = [[arr objectAtIndex:i] mutableCopy];
  321. [self.dataSource addObject:device];
  322. [self requestSensorState:[device.dicListInfo objectForKey:@"DevID"]];
  323. }
  324. }
  325. [self.tbList reloadData];
  326. }else if ([cmdName isEqualToString:@"GetLinkState"]){
  327. NSDictionary *linkStateDic = retDic[@"GetLinkState"];
  328. if (linkStateDic) {
  329. NSString *sensorID = linkStateDic[@"DevID"];
  330. int num = [linkStateDic[@"LinkState"] intValue];
  331. BOOL bOnline = num == 1 ? YES : NO;
  332. for (int i = 0; i < self.dataSource.count; i ++) {
  333. SensorDeviceModel *linkDev = self.dataSource[i];
  334. if ([[linkDev.dicListInfo objectForKey:@"DevID"] isEqualToString:sensorID]) {
  335. linkDev.ifOnline = bOnline;
  336. if (bOnline) {
  337. [self requestSensorDetailStatus:sensorID];
  338. }
  339. break;
  340. }
  341. }
  342. [self.tbList reloadData];
  343. }
  344. }else if ([cmdName isEqualToString:@"InquiryStatus"]){
  345. NSDictionary *inquiryStatusDic = retDic[@"InquiryStatus"];
  346. if (inquiryStatusDic) {
  347. NSString *sensorID = inquiryStatusDic[@"DevID"];
  348. for (int i = 0; i < self.dataSource.count; i ++) {
  349. SensorDeviceModel *linkDev = self.dataSource[i];
  350. if ([[linkDev.dicListInfo objectForKey:@"DevID"] isEqualToString:sensorID]) {
  351. linkDev.dicStatusInfo = [inquiryStatusDic mutableCopy];
  352. }
  353. }
  354. }
  355. [self.tbList reloadData];
  356. }else if ([cmdName isEqualToString:@"DeleteDev"]){
  357. [self.dataSource removeObjectAtIndex:self.tempRow];
  358. [self.tbList reloadData];
  359. }else if ([cmdName isEqualToString:@"ChangeSwitchState"]){
  360. if (msg->seq < self.dataSource.count) {
  361. SensorDeviceModel *model = [self.dataSource objectAtIndex:msg->seq];
  362. NSString *sensorID = [model.dicListInfo objectForKey:@"DevID"];
  363. [self requestSensorDetailStatus:sensorID];
  364. }
  365. }else if ([cmdName isEqualToString:@"ChangeSocketState"]){
  366. if (msg->seq < self.dataSource.count) {
  367. SensorDeviceModel *model = [self.dataSource objectAtIndex:msg->seq];
  368. NSString *sensorID = [model.dicListInfo objectForKey:@"DevID"];
  369. [self requestSensorDetailStatus:sensorID];
  370. }
  371. }else if ([cmdName isEqualToString:@"GetModeConfig"]) {
  372. NSDictionary *modeConfigDic = retDic[@"GetModeConfig"];
  373. NSString *sceneId = modeConfigDic[@"CurMode"];
  374. self.curSceneID = sceneId;
  375. }else if ([cmdName isEqualToString:@"StopAddDev"]){
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. }
  383. #pragma mark - LazyLoad
  384. - (UITableView *)tbList{
  385. if (!_tbList) {
  386. _tbList = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  387. _tbList.delegate = self;
  388. _tbList.dataSource = self;
  389. [_tbList registerClass:[SensorListCell class] forCellReuseIdentifier:kSensorListCell];
  390. [_tbList registerClass:[XMLinkWallSwitchCell class] forCellReuseIdentifier:kXMLinkWallSwitchCell];
  391. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHappened:)];
  392. longPress.minimumPressDuration = 0.5;
  393. [_tbList addGestureRecognizer:longPress];
  394. _tbList.tableFooterView = [[UIView alloc] init];
  395. }
  396. return _tbList;
  397. }
  398. - (NSMutableArray *)dataSource{
  399. if (!_dataSource) {
  400. _dataSource = [NSMutableArray arrayWithCapacity:0];
  401. }
  402. return _dataSource;
  403. }
  404. - (void)dealloc{
  405. FUN_UnRegWnd(self.msgHandle);
  406. }
  407. @end