You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DialogOTATool.h 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // DialogOTATool.h
  3. // Aibrush
  4. //
  5. // Created by steven wu on 2020/8/12.
  6. // Copyright © 2020 taolei. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <CoreBluetooth/CoreBluetooth.h>
  10. //OTA专用的服务UUID,连接上外设后读取peripheral.services数组包含这个UUID,就支持OTA升级
  11. #define OTA_SERVICE_UUID 0xFEF5
  12. ///如下5个特征值都是OTA升级不同阶段,用来向蓝牙写数据使用的
  13. #define OTA_MEM_DEV_UUID @"8082CAA8-41A6-4021-91C6-56F9B954CC34"
  14. #define OTA_GPIO_MAP_UUID @"724249F0-5EC3-4B5F-8804-42345AF08651"
  15. #define OTA_PATCH_LEN_UUID @"9D84B9A3-000C-49D8-9183-855B673FDA31"
  16. #define OTA_PATCH_DATA_UUID @"457871E8-D516-4CA1-9116-57D0B17B9CB2"
  17. ///Dialog有2种OTA升级模式,好牙使用SPOTA,下面这个是SPOTA-Notify特征值
  18. #define OTA_SERV_STATUS_UUID @"5F78DF94-798C-46F5-990A-B3EB6A065C88"
  19. //Dialog的另一种SUOTA升级Notify特征值,好牙暂未使用
  20. //#define OTA_MEM_INFO_UUID @"6C53DB25-47A1-45FE-A022-7C92FB334FD4"
  21. #define memoryType 0x13
  22. #define memoryBank 0
  23. #define spiMOSIAddress 0x06
  24. #define spiMISOAddress 0x05
  25. #define spiCSAddress 0X03
  26. #define spiSCKAddress 0x00
  27. typedef enum {
  28. // Value zero must not be used !! Notifications are sent when status changes.
  29. AiBrush_SRV_STARTED = 0x01, // Valid memory device has been configured by initiator. No sleep state while in this mode
  30. AiBrush_CMP_OK = 0x02, // SPOTA process completed successfully.
  31. AiBrush_SRV_EXIT = 0x03, // Forced exit of SPOTAR service.
  32. AiBrush_CRC_ERR = 0x04, // Overall Patch Data CRC failed
  33. AiBrush_PATCH_LEN_ERR = 0x05, // Received patch Length not equal to PATCH_LEN characteristic value
  34. AiBrush_EXT_MEM_WRITE_ERR= 0x06, // External Mem Error (Writing to external device failed)
  35. AiBrush_INT_MEM_ERR = 0x07, // Internal Mem Error (not enough space for Patch)
  36. AiBrush_INVAL_MEM_TYPE = 0x08, // Invalid memory device
  37. AiBrush_APP_ERROR = 0x09, // Application error
  38. // SUOTAR application specific error codes
  39. AiBrush_IMG_STARTED = 0x10, // SPOTA started for downloading image (SUOTA application)
  40. AiBrush_INVAL_IMG_BANK = 0x11, // Invalid image bank
  41. AiBrush_INVAL_IMG_HDR = 0x12, // Invalid image header
  42. AiBrush_INVAL_IMG_SIZE = 0x13, // Invalid image size
  43. AiBrush_INVAL_PRODUCT_HDR= 0x14, // Invalid product header
  44. AiBrush_SAME_IMG_ERR = 0x15, // Same Image Error
  45. AiBrush_EXT_MEM_READ_ERR = 0x16, // Failed to read from external memory device
  46. } AiBrush_STATUS_VALUES;
  47. @protocol DialogOTAToolDelegate <NSObject>
  48. /*
  49. *返回升级进度至主界面
  50. return update progress to mainscreen
  51. 如果progress=1;则写入失败
  52. */
  53. - (void)returnUpdateProgress:(double)progress;
  54. /*
  55. *返回升级结果至主界面
  56. */
  57. - (void)returnUpdateResult:(BOOL)isSuccess errorMsg:(NSString*)errorMsg ;
  58. @end
  59. @interface DialogOTATool : NSObject
  60. + (instancetype)shared;
  61. @property (nonatomic, weak) id <DialogOTAToolDelegate> delegate;
  62. - (void)OTAupdate:(NSString *)fileStr;
  63. - (void)rebootDevice;
  64. ///如下4个方法:在你的蓝牙中心管理者中调用,用法请参考“好牙”App
  65. @property (nonatomic, weak) CBPeripheral *peripheral;
  66. - (void)analyzeBleValueForCharacteristic:(CBCharacteristic *)characteristic;
  67. - (void)judgeIfDoStepForOTA;
  68. //- (void)judgeIfOTAService:(CBService *)service andOpenOTANotifyForPeripheral:(CBPeripheral *)peripheral;
  69. - (void)judgeIfOTACharacteristics:(NSArray *)characteristics andOpenOTANotifyForPeripheral:(CBPeripheral *)peripheral;
  70. @end