iOS AILinkBleSDK - 蓝牙SDK
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ELMeatProbeCustomDataModel.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //
  2. // ELMeatProbeCustomDataModel.m
  3. // AILinkBleSDK
  4. //
  5. #import "ELMeatProbeCustomDataModel.h"
  6. #import <AILinkBleSDK/NSData+AILinkBle.h>
  7. #import <objc/runtime.h>
  8. @implementation ELMeatProbeCustomDataModel
  9. + (Byte)version {
  10. return 0x02;
  11. }
  12. + (Byte)modelSize {
  13. return 128;//sizeof(ELMeatProbeCustomDataStruct);
  14. }
  15. + (instancetype)modelWithData:(NSData *)data {
  16. if (data.length != self.modelSize) {
  17. NSLog(@"数据长度错误 data:%@", data);
  18. return nil;
  19. }
  20. ELMeatProbeCustomDataModel *model = [[ELMeatProbeCustomDataModel alloc] initWithData:data];
  21. if (model.customStruct.ver != self.version) {
  22. NSLog(@"数据版本错误 data:%@", data);
  23. return nil;
  24. }
  25. return model;
  26. }
  27. - (instancetype)init {
  28. if (self = [super init]) {
  29. memset(&_customStruct, 0, sizeof(_customStruct));
  30. _customStruct.ver = self.class.version;
  31. }
  32. return self;
  33. }
  34. - (instancetype)initWithData:(NSData *)data {
  35. if (self = [self init]) {
  36. memcpy(&_customStruct, data.bytes, sizeof(_customStruct));
  37. }
  38. return self;
  39. }
  40. - (NSData *)dataValue {
  41. Byte bytes[128] = {0x00};
  42. memcpy(bytes, &_customStruct, sizeof(_customStruct));
  43. return [NSData dataWithBytes:bytes length:sizeof(bytes)];
  44. }
  45. - (NSString *)remark {
  46. char *remarkBytes[64] = {0};
  47. memcpy(remarkBytes, _customStruct.remarkBytes, sizeof(_customStruct.remarkBytes));
  48. NSString *str = [NSString stringWithUTF8String:(const char *)remarkBytes];
  49. return str;
  50. }
  51. - (NSString *)setRemark:(NSString *)remark {
  52. NSData *data = [remark dataUsingEncoding:NSUTF8StringEncoding];
  53. if (data.length > 32) {
  54. while (data.length > 29) {
  55. remark = [remark substringToIndex:(remark.length - 1)];
  56. data = [remark dataUsingEncoding:NSUTF8StringEncoding];
  57. }
  58. remark = [remark stringByAppendingString:@"..."];
  59. data = [remark dataUsingEncoding:NSUTF8StringEncoding];
  60. }
  61. Byte *bytes = (Byte *)data.bytes;
  62. NSUInteger total = data.length > 32 ? 32 : data.length;
  63. memset(_customStruct.remarkBytes, 0, 32);
  64. memcpy(_customStruct.remarkBytes, bytes, total);
  65. return [self remark];
  66. }
  67. #pragma mark setter getter
  68. - (NSInteger)ver {
  69. return self.customStruct.ver;
  70. }
  71. - (NSInteger)cookingId {
  72. return self.customStruct.cookingId;
  73. }
  74. - (NSInteger)foodType {
  75. return self.customStruct.foodType;
  76. }
  77. - (NSInteger)foodRawness {
  78. return self.customStruct.foodRawness;
  79. }
  80. - (double)alarmTemperaturePercent {
  81. return self.customStruct.alarmTemperaturePercent;
  82. }
  83. - (NSInteger)alarmTemperature_C {
  84. return self.customStruct.alarmTemperature_C;
  85. }
  86. - (NSInteger)alarmTemperature_F {
  87. return self.customStruct.alarmTemperature_F;
  88. }
  89. - (void)setAlarmTemperaturePercent:(double)alarmTemperaturePercent {
  90. _customStruct.alarmTemperaturePercent = alarmTemperaturePercent;
  91. _customStruct.alarmTemperature_C = _customStruct.targetTemperature_C * alarmTemperaturePercent;
  92. _customStruct.alarmTemperature_F = _customStruct.targetTemperature_F * alarmTemperaturePercent;
  93. }
  94. - (ELDeviceTemperatureUnit)currentUnit {
  95. return self.customStruct.currentUnit;
  96. }
  97. #pragma mark ---- description
  98. - (NSString *)description {
  99. NSMutableString *desc = [NSStringFromClass([self class]) stringByAppendingString:@": {\n"].mutableCopy;
  100. [desc appendString:[NSString stringWithFormat:@"ver: %@,\n", @(self.customStruct.ver)]];
  101. [desc appendString:[NSString stringWithFormat:@"cookingId: %@,\n", @(self.customStruct.cookingId)]];
  102. [desc appendString:[NSString stringWithFormat:@"foodType: %@,\n", @(self.customStruct.foodType)]];
  103. [desc appendString:[NSString stringWithFormat:@"foodRawness: %@,\n", @(self.customStruct.foodRawness)]];
  104. [desc appendString:[NSString stringWithFormat:@"targetTemperature_C: %@,\n", @(self.customStruct.targetTemperature_C)]];
  105. [desc appendString:[NSString stringWithFormat:@"targetTemperature_F: %@,\n", @(self.customStruct.targetTemperature_F)]];
  106. [desc appendString:[NSString stringWithFormat:@"ambientMinTemperature_C: %@,\n", @(self.customStruct.ambientMinTemperature_C)]];
  107. [desc appendString:[NSString stringWithFormat:@"ambientMinTemperature_F: %@,\n", @(self.customStruct.ambientMinTemperature_F)]];
  108. [desc appendString:[NSString stringWithFormat:@"ambientMaxTemperature_C: %@,\n", @(self.customStruct.ambientMaxTemperature_C)]];
  109. [desc appendString:[NSString stringWithFormat:@"ambientMaxTemperature_F: %@,\n", @(self.customStruct.ambientMaxTemperature_F)]];
  110. [desc appendString:[NSString stringWithFormat:@"alarmTemperaturePercent: %@,\n", @(self.alarmTemperaturePercent)]];
  111. [desc appendString:[NSString stringWithFormat:@"timerStart: %@,\n", @(self.customStruct.timerStart)]];
  112. [desc appendString:[NSString stringWithFormat:@"timerEnd: %@,\n", @(self.customStruct.timerEnd)]];
  113. [desc appendString:[NSString stringWithFormat:@"alarmTemperature_C: %@,\n", @(self.customStruct.alarmTemperature_C)]];
  114. [desc appendString:[NSString stringWithFormat:@"alarmTemperature_F: %@,\n", @(self.customStruct.alarmTemperature_F)]];
  115. [desc appendString:[NSString stringWithFormat:@"currentUnit: %@,\n", @(self.customStruct.currentUnit)]];
  116. [desc appendString:[NSString stringWithFormat:@"remark: %@,\n", self.remark]];
  117. [desc appendString:@"}"];
  118. return desc;
  119. }
  120. - (NSString *)debugDescription {
  121. return [self description];
  122. }
  123. @end