feature():1.修改dyglucose的消息发送模式适配新版程序 2.删除用不到的读卡库引用代码

This commit is contained in:
lvwang2002 2024-03-29 01:09:57 +08:00
parent bb1ee3228a
commit d25c64ea51
3 changed files with 377 additions and 329 deletions

View File

@ -17,14 +17,15 @@
#import "ENCholesterolDevice.h" #import "ENCholesterolDevice.h"
#import "RCTEventEmitter.h" #import "RCTEventEmitter.h"
#if TARGET_IPHONE_SIMULATOR//模拟器 //#if TARGET_IPHONE_SIMULATOR//模拟器
//真机
@interface RNMethodModule : NSObject<RCTBridgeModule,DeviceManagerProtocol,BLEDeviceProtocol,ENGlucoDeviceProtocal,ENGGlucoDeviceProtocal,ENBPDeviceProtocal,ENCholesterolDeviceProtocal> @interface RNMethodModule : NSObject<RCTBridgeModule,DeviceManagerProtocol,BLEDeviceProtocol,ENGlucoDeviceProtocal,ENGGlucoDeviceProtocal,ENBPDeviceProtocal,ENCholesterolDeviceProtocal>
#elif TARGET_OS_IPHONE//真机 //#elif TARGET_OS_IPHONE//真机
#import "INVSSDK/INVSSDK.h" //#import "INVSSDK/INVSSDK.h"
#import "INVSSDK/NSString+ThreeDES.h" //#import "INVSSDK/NSString+ThreeDES.h"
@interface RNMethodModule : NSObject<RCTBridgeModule,DeviceManagerProtocol,BLEDeviceProtocol,ENGlucoDeviceProtocal,ENGGlucoDeviceProtocal,ENBPDeviceProtocal,ENCholesterolDeviceProtocal,BR_Callback> //@interface RNMethodModule : NSObject<RCTBridgeModule,DeviceManagerProtocol,BLEDeviceProtocol,ENGlucoDeviceProtocal,ENGGlucoDeviceProtocal,ENBPDeviceProtocal,ENCholesterolDeviceProtocal,BR_Callback>
#endif //#endif

View File

@ -36,7 +36,7 @@
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
INVSBleTool *_bletool; // INVSBleTool *_bletool;
#endif #endif
BLEDevice *_cardDevice; BLEDevice *_cardDevice;
Boolean _isUpdateDeviceList; Boolean _isUpdateDeviceList;
@ -66,7 +66,7 @@ RCT_EXPORT_MODULE();
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
_bletool=[[INVSBleTool alloc]init:self]; // _bletool=[[INVSBleTool alloc]init:self];
#endif #endif
@ -757,7 +757,7 @@ RCT_REMAP_METHOD(stopCardReaderScan,
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
[_bletool disconnectBt]; // [_bletool disconnectBt];
#endif #endif
// if(!_cardDevice){ // if(!_cardDevice){
@ -789,7 +789,7 @@ RCT_EXPORT_METHOD(connectCardReader:(NSString *)uuid
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
[_bletool connectBt:[device getPeripheral]]; // [_bletool connectBt:[device getPeripheral]];
#endif #endif
_cardDevice = device; _cardDevice = device;
@ -819,7 +819,7 @@ RCT_EXPORT_METHOD(connectCardReader:(NSString *)uuid
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
[_bletool disconnectBt]; // [_bletool disconnectBt];
#endif #endif
return; return;
} }
@ -855,37 +855,37 @@ RCT_REMAP_METHOD(readCard,
#if TARGET_IPHONE_SIMULATOR//模拟器 #if TARGET_IPHONE_SIMULATOR//模拟器
#elif TARGET_OS_IPHONE//真机 #elif TARGET_OS_IPHONE//真机
if(!_bletool){ // if(!_bletool){
reject(@"400",@"no device",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]); // reject(@"400",@"no device",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]);
return; // return;
} // }
//
NSDictionary *obj = [_bletool readCard]; // NSDictionary *obj = [_bletool readCard];
if(!obj){ // if(!obj){
reject(@"400",@"no device",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]); // reject(@"400",@"no device",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]);
return; // return;
} // }
//
// NSMutableString *resultContent = [[NSMutableString alloc] init]; //// NSMutableString *resultContent = [[NSMutableString alloc] init];
//
NSInteger resultFlag = [obj[@"resultFlag"] integerValue]; // NSInteger resultFlag = [obj[@"resultFlag"] integerValue];
if(resultFlag == -1){ // if(resultFlag == -1){
reject(@"400",@"no data",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]); // reject(@"400",@"no data",[NSError errorWithDomain:@"device" code:400 userInfo:@{}]);
}else{ // }else{
NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithCapacity:10]; // NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithCapacity:10];
//
[info setObject:obj[@"partyName"] forKey:@"name"]; // [info setObject:obj[@"partyName"] forKey:@"name"];
[info setObject:obj[@"certAddress"] forKey:@"address"]; // [info setObject:obj[@"certAddress"] forKey:@"address"];
[info setObject:obj[@"bornDay"] forKey:@"birth"]; // [info setObject:obj[@"bornDay"] forKey:@"birth"];
[info setObject:obj[@"expDate"] forKey:@"end"]; // [info setObject:obj[@"expDate"] forKey:@"end"];
[info setObject:obj[@"certNumber"] forKey:@"idNo"]; // [info setObject:obj[@"certNumber"] forKey:@"idNo"];
[info setObject:obj[@"nation"] forKey:@"nation"]; // [info setObject:obj[@"nation"] forKey:@"nation"];
[info setObject:obj[@"certOrg"] forKey:@"police"]; // [info setObject:obj[@"certOrg"] forKey:@"police"];
[info setObject:obj[@"gender"] forKey:@"sex"]; // [info setObject:obj[@"gender"] forKey:@"sex"];
[info setObject:obj[@"effDate"] forKey:@"start"]; // [info setObject:obj[@"effDate"] forKey:@"start"];
//
resolve([info copy]); // resolve([info copy]);
} // }
#endif #endif

View File

@ -58,6 +58,8 @@ const GET_BATTERY = 16;
let driver = null; let driver = null;
export default class RNDYGlucoseDriver { export default class RNDYGlucoseDriver {
subscriptionMap = {};
constructor() { constructor() {
this._eventMap = { this._eventMap = {
@ -390,7 +392,11 @@ export default class RNDYGlucoseDriver{
if (dataList.length >= count) { if (dataList.length >= count) {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(null, dataList); finish(null, dataList);
return; return;
} else { } else {
@ -398,19 +404,27 @@ export default class RNDYGlucoseDriver{
} }
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')) finish(new Error('receive data time out'))
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
}; };
DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA,receiveData); this.subscriptionMap[DYG_ON_GET_ALL_DATA] = DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA, receiveData);
await this._commadTimeInterval(COMMAND_TIME_INTERVAL); await this._commadTimeInterval(COMMAND_TIME_INTERVAL);
MethodModule.getAllDataDYG(deviceMac, GET_ALL_DATA); MethodModule.getAllDataDYG(deviceMac, GET_ALL_DATA);
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')) finish(new Error('receive data time out'))
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
@ -450,7 +464,11 @@ export default class RNDYGlucoseDriver{
console.log(TAG, 'rcv data count', dataList.length); console.log(TAG, 'rcv data count', dataList.length);
if (dataList.length >= count) { if (dataList.length >= count) {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(null, dataList); finish(null, dataList);
return; return;
} else { } else {
@ -458,19 +476,28 @@ export default class RNDYGlucoseDriver{
} }
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')) finish(new Error('receive data time out'))
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
}; };
DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA,receiveData); this.subscriptionMap[DYG_ON_GET_ALL_DATA] = DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA, receiveData);
await this._commadTimeInterval(COMMAND_TIME_INTERVAL); await this._commadTimeInterval(COMMAND_TIME_INTERVAL);
MethodModule.getAllDataFromIndexDYG(deviceMac, GET_ALL_DATA_FROM_INDEX, index); MethodModule.getAllDataFromIndexDYG(deviceMac, GET_ALL_DATA_FROM_INDEX, index);
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')) finish(new Error('receive data time out'))
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
@ -508,7 +535,11 @@ export default class RNDYGlucoseDriver{
dataList = dataList.concat(deviceInfo.dataList); dataList = dataList.concat(deviceInfo.dataList);
console.log(TAG, 'rcv device data length:', dataList.length); console.log(TAG, 'rcv device data length:', dataList.length);
if (dataList.length >= count) { if (dataList.length >= count) {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(null, dataList); finish(null, dataList);
return; return;
} else { } else {
@ -516,19 +547,27 @@ export default class RNDYGlucoseDriver{
} }
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')); finish(new Error('receive data time out'));
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
}; };
DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA,receiveData); this.subscriptionMap[DYG_ON_GET_ALL_DATA] = DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA, receiveData);
await this._commadTimeInterval(COMMAND_TIME_INTERVAL); await this._commadTimeInterval(COMMAND_TIME_INTERVAL);
MethodModule.getNumberDataFromIndexDYG(deviceMac, GET_NUMBER_DATA_FROM_INDEX, index, count); MethodModule.getNumberDataFromIndexDYG(deviceMac, GET_NUMBER_DATA_FROM_INDEX, index, count);
timer = setTimeout(() => { timer = setTimeout(() => {
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA,receiveData); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA, receiveData);
if (this.subscriptionMap['DYG_ON_GET_ALL_DATA']) {
this.subscriptionMap['DYG_ON_GET_ALL_DATA'].remove();
delete this.subscriptionMap['DYG_ON_GET_ALL_DATA']; // 可选,从映射中删除键,避免内存泄漏
}
finish(new Error('receive data time out')); finish(new Error('receive data time out'));
}, PROGRESS_TIME_INTERVAL); }, PROGRESS_TIME_INTERVAL);
@ -638,26 +677,26 @@ export default class RNDYGlucoseDriver{
console.log(TAG, 'created channel'); console.log(TAG, 'created channel');
this._executeEvent(DYG_CREATED_CHANNEL, deviceInfo); this._executeEvent(DYG_CREATED_CHANNEL, deviceInfo);
}; };
DeviceEventEmitter.addListener(DYG_CREATED_CHANNEL,this._createChannel); this.subscriptionMap['DYG_CREATED_CHANNEL'] = DeviceEventEmitter.addListener(DYG_CREATED_CHANNEL, this._createChannel);
this._onDoAuthorization = (deviceInfo) => { this._onDoAuthorization = (deviceInfo) => {
console.log(TAG, 'received ' + DYG_ON_DO_AUTHORIZATION); console.log(TAG, 'received ' + DYG_ON_DO_AUTHORIZATION);
this._executeEvent(DYG_ON_DO_AUTHORIZATION, deviceInfo); this._executeEvent(DYG_ON_DO_AUTHORIZATION, deviceInfo);
}; };
DeviceEventEmitter.addListener(DYG_ON_DO_AUTHORIZATION,this._onDoAuthorization); this.subscriptionMap[DYG_ON_DO_AUTHORIZATION] = DeviceEventEmitter.addListener(DYG_ON_DO_AUTHORIZATION, this._onDoAuthorization);
this._onGetBattery = (deviceInfo) => { this._onGetBattery = (deviceInfo) => {
console.log(TAG, 'received ' + DYG_ON_GET_BATTERY); console.log(TAG, 'received ' + DYG_ON_GET_BATTERY);
this._executeEvent(DYG_ON_GET_BATTERY, deviceInfo); this._executeEvent(DYG_ON_GET_BATTERY, deviceInfo);
}; };
DeviceEventEmitter.addListener(DYG_ON_GET_BATTERY,this._onGetBattery); this.subscriptionMap[DYG_ON_GET_BATTERY] = DeviceEventEmitter.addListener(DYG_ON_GET_BATTERY, this._onGetBattery);
this._onGetAllDataCount = (deviceInfo) => { this._onGetAllDataCount = (deviceInfo) => {
console.log(TAG, 'received ' + DYG_ON_GET_ALL_DATA_COUNT); console.log(TAG, 'received ' + DYG_ON_GET_ALL_DATA_COUNT);
this._executeEvent(DYG_ON_GET_ALL_DATA_COUNT, deviceInfo); this._executeEvent(DYG_ON_GET_ALL_DATA_COUNT, deviceInfo);
}; };
DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA_COUNT,this._onGetAllDataCount); this.subscriptionMap[DYG_ON_GET_ALL_DATA_COUNT] = DeviceEventEmitter.addListener(DYG_ON_GET_ALL_DATA_COUNT, this._onGetAllDataCount);
this._updateDeviceList = (deviceInfos) => { this._updateDeviceList = (deviceInfos) => {
// console.log(TAG,deviceInfos); // console.log(TAG,deviceInfos);
@ -670,24 +709,24 @@ export default class RNDYGlucoseDriver{
this._onUpdateDeviceList(deviceList); this._onUpdateDeviceList(deviceList);
}; };
DeviceEventEmitter.addListener(UPDATE_DEVICE_LIST,this._updateDeviceList); this.subscriptionMap[UPDATE_DEVICE_LIST] = DeviceEventEmitter.addListener(UPDATE_DEVICE_LIST, this._updateDeviceList);
/** 获得当前监控的状态 */ /** 获得当前监控的状态 */
this._onGetMonitorStatus = (deviceInfo) => { this._onGetMonitorStatus = (deviceInfo) => {
this._executeEvent(DYG_ON_GET_MONITOR_STATUS, deviceInfo); this._executeEvent(DYG_ON_GET_MONITOR_STATUS, deviceInfo);
} }
DeviceEventEmitter.addListener(DYG_ON_GET_MONITOR_STATUS,this._onGetMonitorStatus); this.subscriptionMap[DYG_ON_GET_MONITOR_STATUS] = DeviceEventEmitter.addListener(DYG_ON_GET_MONITOR_STATUS, this._onGetMonitorStatus);
/** 获得是否已经开始监控 */ /** 获得是否已经开始监控 */
this._onStartMonitor = (deviceInfo) => { this._onStartMonitor = (deviceInfo) => {
this._executeEvent(DYG_ON_START_MONITOR, deviceInfo); this._executeEvent(DYG_ON_START_MONITOR, deviceInfo);
} }
DeviceEventEmitter.addListener(DYG_ON_START_MONITOR,this._onStartMonitor); this.subscriptionMap[DYG_ON_START_MONITOR] = DeviceEventEmitter.addListener(DYG_ON_START_MONITOR, this._onStartMonitor);
this._onStopMonitor = (deviceInfo) => { this._onStopMonitor = (deviceInfo) => {
this._executeEvent(DYG_ON_STOP_MONITOR, deviceInfo); this._executeEvent(DYG_ON_STOP_MONITOR, deviceInfo);
} }
DeviceEventEmitter.addListener(DYG_ON_STOP_MONITOR,this._onStopMonitor); this.subscriptionMap[DYG_ON_STOP_MONITOR] = DeviceEventEmitter.addListener(DYG_ON_STOP_MONITOR, this._onStopMonitor);
@ -699,20 +738,28 @@ export default class RNDYGlucoseDriver{
this._onUpdateNewData(deviceInfo.index, deviceInfo.value); this._onUpdateNewData(deviceInfo.index, deviceInfo.value);
} }
DeviceEventEmitter.addListener(DYG_ON_UPDATE_NEW_DATA,this._updateNewData); this.subscriptionMap[DYG_ON_UPDATE_NEW_DATA] = DeviceEventEmitter.addListener(DYG_ON_UPDATE_NEW_DATA, this._updateNewData);
} }
endMonitorDriverEvent() { endMonitorDriverEvent() {
DeviceEventEmitter.removeListener(DYG_CREATED_CHANNEL,this._createChannel); // DeviceEventEmitter.removeListener(DYG_CREATED_CHANNEL,this._createChannel);
DeviceEventEmitter.removeListener(DYG_ON_DO_AUTHORIZATION,this._onDoAuthorization); // DeviceEventEmitter.removeListener(DYG_ON_DO_AUTHORIZATION,this._onDoAuthorization);
DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA_COUNT,this._onGetAllDataCount); // DeviceEventEmitter.removeListener(DYG_ON_GET_ALL_DATA_COUNT,this._onGetAllDataCount);
DeviceEventEmitter.removeListener(DYG_ON_GET_MONITOR_STATUS,this._onGetMonitorStatus); // DeviceEventEmitter.removeListener(DYG_ON_GET_MONITOR_STATUS,this._onGetMonitorStatus);
DeviceEventEmitter.removeListener(UPDATE_DEVICE_LIST,this._updateDeviceList); // DeviceEventEmitter.removeListener(UPDATE_DEVICE_LIST,this._updateDeviceList);
DeviceEventEmitter.removeListener(DYG_ON_START_MONITOR,this._onStartMonitor); // DeviceEventEmitter.removeListener(DYG_ON_START_MONITOR,this._onStartMonitor);
DeviceEventEmitter.removeListener(DYG_ON_STOP_MONITOR,this._onStopMonitor); // DeviceEventEmitter.removeListener(DYG_ON_STOP_MONITOR,this._onStopMonitor);
DeviceEventEmitter.removeListener(DYG_ON_UPDATE_NEW_DATA,this._updateNewData); // DeviceEventEmitter.removeListener(DYG_ON_UPDATE_NEW_DATA,this._updateNewData);
DeviceEventEmitter.removeListener(DYG_ON_GET_BATTERY,this._onGetBattery); // DeviceEventEmitter.removeListener(DYG_ON_GET_BATTERY,this._onGetBattery);
// 移除监听器
Object.keys(this.subscriptionMap).forEach(key => {
this.subscriptionMap[key].remove();
});
// 清除订阅对象记录,避免内存泄漏
this.subscriptionMap = {};
} }
} }