Skip to content

Commit

Permalink
Update AssemblyFileTool and OTA tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Heptapods-Y committed Feb 7, 2024
1 parent aaa5f98 commit 835c8aa
Show file tree
Hide file tree
Showing 319 changed files with 25,631 additions and 0 deletions.
Binary file not shown.
Binary file removed Android Tool/CH583_OTA Upgrade Tool Manual.pdf
Binary file not shown.
Binary file removed Android Tool/CH583_OTA升级工具使用说明.pdf
Binary file not shown.
Binary file removed Android Tool/OTA Tool source/CH583Update.zip
Binary file not shown.
Binary file removed Android Tool/OTA Tool/CH583 OTA Tool.apk
Binary file not shown.
Binary file removed Android Tool/WCH蓝牙空中升级(BLE OTA).pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Tool/OTA_Tool/BLE_OTA_Android/demo/OTAUpdate.zip
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>BLEOTALibrary.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>7</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// BLEOTACmd.h
// BLEOTALibrary
//
// Created by moyun on 2022/4/13.
//

#import <Foundation/Foundation.h>
#import "Constant.h"

NS_ASSUME_NONNULL_BEGIN

@interface BLEOTACmd : NSObject

+ (NSInteger)updateMTU:(NSInteger)mtu;

+ (void)updateAddressBase:(ChipType)type;

+ (NSData *)getImageInfoCommand;

+ (NSData *)getEraseCommand:(NSInteger)addr block:(NSInteger)block;

+ (NSData *)getProgrammeCommand:(NSInteger)addr data:(NSData *)bytes;

+ (NSData *)getVerifyCommand:(NSInteger)addr data:(NSData *)bytes;


+ (NSData *)getEndCommand;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// BLEOTACmd.m
// BLEOTALibrary
//
// Created by moyun on 2022/4/13.
//

#import "BLEOTACmd.h"


#define CMD_ISP_PROGRAM 0x80
#define CMD_ISP_ERASE 0x81
#define CMD_ISP_VERIFY 0x82
#define CMD_ISP_END 0x83
#define CMD_ISP_INFO 0x84


NSInteger DATA_LEN = 20;
//地址需要除以它
//573,583的地址除以16,CH579除以4
NSInteger ADDRESS_BASE = 16;

@implementation BLEOTACmd

//为了提高发送速度编程前交换MTU
+ (NSInteger)updateMTU:(NSInteger)mtu {
DATA_LEN = mtu;
return DATA_LEN;
}

+ (void)updateAddressBase:(ChipType)type {
if (type == ChipType_CH579 || type == ChipType_UNKNOW) {
ADDRESS_BASE = 4;
}else if (type == ChipType_CH573) {
ADDRESS_BASE = 16;
}else if (type == ChipType_CH583) {
ADDRESS_BASE = 16;
}
}

+ (NSData *)getImageInfoCommand {

// struct Info info = {};
// info.cmd = 0x84;
// info.len = 0x12;
//
// Byte buf[IAP_LEN - 2] = {};
// memset(buf, 0x00, IAP_LEN - 2);
// memmove(info.buf, buf, IAP_LEN - 2);
//
// NSData *infoCmd = [[NSData alloc] initWithBytes:&info length:sizeof(info)];

Byte byteBuffer[IAP_LEN] = {};
memset(byteBuffer, 0, IAP_LEN);

byteBuffer[0] = CMD_ISP_INFO;
byteBuffer[1] = IAP_LEN - 2;

NSData *data = [[NSData alloc] initWithBytes:byteBuffer length:IAP_LEN];
return data;
}

+ (NSData *)getEraseCommand:(NSInteger)addr block:(NSInteger)block {

Byte byteBuffer[IAP_LEN] = {};
memset(byteBuffer, 0, IAP_LEN);

byteBuffer[0] = CMD_ISP_ERASE;
byteBuffer[1] = 0x00;
byteBuffer[2] = addr / ADDRESS_BASE;
byteBuffer[3] = ((addr / ADDRESS_BASE) >> 8);
byteBuffer[4] = block;
byteBuffer[5] = block >> 8;

NSData *data = [[NSData alloc] initWithBytes:byteBuffer length:IAP_LEN];
return data;
}

+ (NSData *)getProgrammeCommand:(NSInteger)addr data:(NSData *)bytes {
Byte *byteBuffer = malloc(DATA_LEN);
memset(byteBuffer, 0, DATA_LEN);

byteBuffer[0] = CMD_ISP_PROGRAM;
byteBuffer[1] = bytes.length;
byteBuffer[2] = addr / ADDRESS_BASE;
byteBuffer[3] = ((addr / ADDRESS_BASE) >> 8);

// NSLog(@"编程地址:%ld offset:%ld", addr / ADDRESS_BASE, addr);

Byte *dataByte = (Byte *)[bytes bytes];
memmove(byteBuffer + 4, dataByte, bytes.length);

NSData *data = [[NSData alloc] initWithBytes:byteBuffer length:DATA_LEN];
free(byteBuffer);

return data;
}


+ (NSData *)getVerifyCommand:(NSInteger)addr data:(NSData *)bytes {
Byte *byteBuffer = malloc(DATA_LEN);
memset(byteBuffer, 0, DATA_LEN);

byteBuffer[0] = CMD_ISP_VERIFY;
byteBuffer[1] = bytes.length;
byteBuffer[2] = addr / ADDRESS_BASE;
byteBuffer[3] = ((addr / ADDRESS_BASE) >> 8);

// NSLog(@"认证地址:%ld offset:%ld", addr / ADDRESS_BASE, addr);

Byte *dataByte = (Byte *)[bytes bytes];
memmove(byteBuffer + 4, dataByte, bytes.length);

NSData *data = [[NSData alloc] initWithBytes:byteBuffer length:DATA_LEN];
free(byteBuffer);

return data;
}


+ (NSData *)getEndCommand {
Byte byteBuffer[IAP_LEN] = {};
memset(byteBuffer, 0, IAP_LEN);

byteBuffer[0] = CMD_ISP_END;
byteBuffer[1] = IAP_LEN - 2;

NSData *data = [[NSData alloc] initWithBytes:byteBuffer length:IAP_LEN];
return data;
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// BLEOTALibrary.h
// BLEOTALibrary
//
// Created by moyun on 2022/4/7.
//

#import <Foundation/Foundation.h>

//! Project version number for BLEOTALibrary.
FOUNDATION_EXPORT double BLEOTALibraryVersionNumber;

//! Project version string for BLEOTALibrary.
FOUNDATION_EXPORT const unsigned char BLEOTALibraryVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <BLEOTALibrary/PublicHeader.h>

#import "BLEOTAManager.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// BLEOTAManager.h
// BLEOTALibrary
//
// Created by moyun on 2022/4/7.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "CurrentImageObject.h"

//OTA升级进度类型
typedef NS_ENUM(NSUInteger, progressType) {
progressType_Erase = 0,
progressType_EraseSuccess = 1,
progressType_EraseFailed = 2,
progressType_Program = 3,
progressType_ProgramWait = 4,
progressType_ProgramSuccess = 5,
progressType_ProgramFailed = 6,
progressType_Verify = 7,
progressType_VerifyWait = 8,
progressType_VerifySuccess = 9,
progressType_VerifyFailed = 10,
progressType_End = 11,
};

typedef void(^writeDataCallBack)(NSInteger);
typedef void(^OTAProgressCallBack)(progressType);
typedef void(^rssiCallBack)(NSNumber *);

#pragma mark - 代理方法
@protocol BLEOTADelegate <NSObject>

//蓝牙状态回调
- (void)BLEManagerDidUpdateState:(NSError *)error;

//监听设备连接状态变更通知
- (void)BLEManagerDidPeripheralConnectUpateState:(CBPeripheral *)peripheral error:(NSError *)error;

//发现设备回调
- (void)BLEManagerDidDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI;

//发现服务回调
- (void)BLEManagerPeriphearl:(CBPeripheral *)peripheral services:(NSArray<CBService *> *)services error:(NSError *)error;

//发现服务特征回调
- (void)BLEManagerService:(CBService *)service characteristics:(NSArray<CBCharacteristic *> *)characteristics error:(NSError *)error;

//特征通道的值发生改变
- (void)BLEManagerUpdateValueForCharacteristic:(CBPeripheral *)peripheral Characteristic:(CBCharacteristic *)characteristic error:(NSError *)error;

@end

@interface BLEOTAManager : NSObject

//代理对象
@property (nonatomic, weak) id<BLEOTADelegate> delegate;

//开启调试信息
@property (nonatomic, assign)BOOL isDebug;

//可以根据传入的UUID扫描服务
@property (nonatomic, strong) NSArray<CBUUID *> * serviceUUIDS;

/*
*@method 生成单列
*/
+ (instancetype) shareInstance;

/*
*@method 开始扫描
*@param serviceUUIDs 指定的UUID服务
*@param scanRuler 扫描过滤规则
*/
- (void)startScan:(NSArray<CBUUID *> *)serviceUUIDs options:(NSDictionary *)scanRuler;

/*
*@method 停止扫描
*/
- (void)stopScan;

/*
*@method 连接设备
*/
- (void)connect:(CBPeripheral *)peripheral;

/*
*@method 断开连接
*/
- (void)disconnect:(CBPeripheral *)peripheral;

/*
*@method 获取当前连接的蓝牙设备硬件信息
*@discussion 返回当前硬件设备的属性对象
*/
- (CurrentImageObject *)getCurrentImageInfo;

/*
*@method 设置芯片类型
*@discussion 对于芯片类型没有获取到的设备建议手动设置
*/
- (void)setChipType:(ChipType)type;

/*
*@method hex文件数据转bin
*@param data hex文件的NSData
*@discussion 返回bin格式的data
*/
- (NSData *)hex2BinData:(NSData *)data;

/*
*@method 开始OTA升级
*@param data 转换成bin后的NSData
*@param eraseAddr 擦除地址
*@param writeCallBack 升级步骤回调
*@param progressCallBack 进度条回调
*/
- (void)startOTAUpdate:(NSData *)data eraseAddr:(NSInteger)eraseAddr writeCallBack:(writeDataCallBack)writeBlock progressCallBack:(OTAProgressCallBack)progressBlock;

/*
*@method 取消OTA升级
*/
- (void)cancleOTAUpdate;

/*
*@method 读取信号
@param peripheral 外设对象
@param rssiCallBack 信号强度回调
*/
- (void)readRSSI:(CBPeripheral *)peripheral rssiCallBack:(rssiCallBack)rssiBlock;

@end
Loading

0 comments on commit 835c8aa

Please sign in to comment.