PictureFileConfig.mm 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // PictureFileConfig.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/16.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #define MAX_FINDFILE_SIZE 10000 //每次搜索的最大文件数量,可以根据需要自行设置
  9. #import "PictureFileConfig.h"
  10. #import "OPSCalendar.h"
  11. #import "FunSDK/FunSDK.h"
  12. @interface PictureFileConfig ()
  13. {
  14. OPSCalendar canendar; //查询一个月内哪些天有图片
  15. NSMutableArray *fileArray; //按文件搜索某一天的录像数组结果
  16. NSMutableArray *dateArray; //搜索某一个月哪些天有图片的结果数组
  17. }
  18. @end
  19. @implementation PictureFileConfig
  20. #pragma mark - 搜索传入这一天的设备图片
  21. - (void)getDevicePictureByFile:(NSDate*)date {
  22. fileArray = [[NSMutableArray alloc] initWithCapacity:0];
  23. //获取通道
  24. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  25. NSDateComponents* components = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
  26. //开内存
  27. H264_DVR_FINDINFO info;
  28. memset(&info, 0, sizeof(info));
  29. info.nChannelN0 = channel.channelNumber;
  30. info.nFileType = SDK_PIC_ALL; //查询全部类型的图片
  31. //开始时间
  32. info.startTime.dwYear = (int)[components year];
  33. info.startTime.dwMonth = (int)[components month];
  34. info.startTime.dwDay = (int)[components day];
  35. info.startTime.dwHour = 0; //小时、分钟、秒可以根据需要进行修改
  36. info.startTime.dwMinute = 0;
  37. info.startTime.dwSecond = 0;
  38. //结束时间
  39. info.endTime.dwYear = (int)[components year];
  40. info.endTime.dwMonth = (int)[components month];
  41. info.endTime.dwDay = (int)[components day];
  42. info.endTime.dwHour = 23;
  43. info.endTime.dwMinute = 59;
  44. info.endTime.dwSecond = 59;
  45. //开始搜索设备图片
  46. FUN_DevFindFile(self.MsgHandle, SZSTR(channel.deviceMac), &info, MAX_FINDFILE_SIZE);
  47. }
  48. #pragma mark - 获取一个月内有图片的日期
  49. - (void)getMonthPictureDate:(NSDate *)date {
  50. dateArray = [[NSMutableArray alloc] initWithCapacity:0];
  51. //获取通道
  52. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  53. NSDateComponents * components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date];
  54. NSString * cmd = [NSString stringWithFormat:@"{\"Name\":\"OPSCalendar\",\"OPSCalendar\": {\"Event\": \"*\",\"FileType\": \"jpg\",\"Month\": %ld ,\"Rev\": \"\",\"Year\": %ld},\"SessionID\": \"0x00000001\"}",(long)[components month],(long)[components year]];
  55. FUN_DevCmdGeneral(self.MsgHandle,SZSTR(channel.deviceMac),1446, "OPSCalendar",0, 5000,strdup(SZSTR(cmd)));
  56. //解析配置用到的对象初始化
  57. CfgParam* calendarCfg = [[CfgParam alloc] initWithName:NSSTR(canendar.Name()) andDevId:channel.deviceMac andChannel:channel.channelNumber andConfig:&canendar andOnce:YES andSaveLocal:YES];
  58. [self AddCmdfig:calendarCfg];
  59. }
  60. #pragma mark - 读取各种请求的结果
  61. - (NSMutableArray *)getPictureFileArray { //获取请求到的图片数组
  62. return [fileArray mutableCopy];
  63. }
  64. - (NSMutableArray *)getMonthPictureArray { //获取设备一个月内哪些天有图片的数组
  65. int mask = canendar.Mask.Value();
  66. for( int i=0; i < 32; i++ ){
  67. //判断一个月31天内,哪一天有录像,31位二进制,等于一的日期有录像
  68. if ((mask & (1<<i)) && mask>0) {
  69. NSDateComponents * components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
  70. NSString* strDate = [NSString stringWithFormat:@"%04ld-%02ld-%02d",components.year, components.month, i+1];
  71. [dateArray addObject:strDate];
  72. }
  73. }
  74. return dateArray;
  75. }
  76. #pragma mark - 获取设备图片回调
  77. -(void)OnGetConfig:(CfgParam *)param{
  78. if ([param.name isEqualToString:NSSTR(canendar.Name())]) {
  79. NSLog(@"Mask = %d",canendar.Mask.Value());
  80. if ([self.delegate respondsToSelector:@selector(getPictureResult:)]) {
  81. [self.delegate getPictureResult:param.errorCode];
  82. }
  83. }
  84. };
  85. #pragma mark - 请求图片结果回调信息
  86. -(void)OnFunSDKResult:(NSNumber *) pParam{
  87. [super OnFunSDKResult:pParam];
  88. NSInteger nAddr = [pParam integerValue];
  89. MsgContent *msg = (MsgContent *)nAddr;
  90. switch (msg->id) {
  91. #pragma mark 图片查询结果回调
  92. case EMSG_DEV_FIND_FILE: {
  93. if (msg->param1 < 0) {
  94. [MessageUI ShowErrorInt:msg->param1];
  95. }else{
  96. [SVProgressHUD dismiss];
  97. int num = msg->param1;
  98. H264_DVR_FILE_DATA *pFile = (H264_DVR_FILE_DATA *)msg->pObject;
  99. for (int i=0; i<num; i++) {
  100. PictureInfo *pictureInfo = [PictureInfo new];
  101. pictureInfo.channelNo = pFile[i].ch;
  102. pictureInfo.fileType = 0; //文件类型是文件名中 中括号中的大写字母表示,例如:[M] 移动侦测,[H]手动录像,[*]普通录像等等
  103. pictureInfo.fileName = [NSString stringWithUTF8String:pFile[i].sFileName];
  104. pictureInfo.fileSize = pFile[i].size;
  105. XM_SYSTEM_TIME timeBegin;
  106. memcpy(&timeBegin, (char*)&(pFile[i].stBeginTime), sizeof(SDK_SYSTEM_TIME));
  107. pictureInfo.timeBegin = timeBegin;
  108. XM_SYSTEM_TIME timeEnd;
  109. memcpy(&timeEnd, (char*)&(pFile[i].stEndTime), sizeof(SDK_SYSTEM_TIME));
  110. pictureInfo.timeEnd = timeEnd;
  111. [fileArray addObject:pictureInfo];
  112. }
  113. }
  114. if ([self.delegate respondsToSelector:@selector(getPictureResult:)]) {
  115. [self.delegate getPictureResult:msg->param1];
  116. }
  117. }
  118. break;
  119. case EMSG_DEV_CMD_EN: {
  120. }
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. @end