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

@protocol BR_Callback <NSObject, CBCentralManagerDelegate>

@optional
- (void) BR_getPeripheral:(CBPeripheral *)peripheral;
-(void)BR_connectResult:(BOOL)isconnected;//类似这样的方法
@end

@interface SdsesBleTool : NSObject<CBCentralManagerDelegate, CBPeripheralDelegate> {
    
    long gRq,gBh;

}

-(SdsesBleTool*) init:(id)myself  ;
-(NSDictionary*)readCert;
-(Boolean) connectBt:(CBPeripheral *)bt :(NSString*) adName usingCBManager:(CBCentralManager*)cbmanager;
-(bool)disconnectBt;

//receverdFuncton
-(NSInteger)id2GetBmpBuff:(char *)wltBuff  :(char *)bmpBuff;

- (NSInteger)id2ShakeHand;
- (Boolean)id2InteractionCheck:(Byte*)key;

- (NSInteger)id2ReadCard:(Byte *)id2DataBuff;

- (NSInteger)id2ReadCardEncrypt:(Byte*)encryptId2Data;
-(NSInteger)id2GetBmpBuff:(char *)wltBuff  :(char *)bmpBuff;

- (NSDictionary* )  readSIMInfo:(Byte) simType ;
- (NSInteger )  writeBlankSim:(Byte*)data1 :(Byte) len1 :(Byte*)data2 :(Byte) len2;
- (NSInteger )  writeSmsCenter:(Byte*)data :(Byte) len;
- (NSDictionary* )  readICCID;





//private function

//@property (nonatomic, retain) CBCentralManager *manager;
@property (nonatomic, retain) id<BR_Callback> delegate;
@property (strong, nonatomic) NSMutableArray *peripherals;
@property (nonatomic, retain) CBPeripheral *activePeripheral;

-(void) stopScan;
-(int) ScanDeviceList:(float)timeout ;
-(void) scanTimer: (NSTimer *)timer;

-(NSMutableArray*)scanDeviceList:(float)scanTime;
-(void) write:(CBPeripheral *)peripheral data:(NSData *)data;
-(void) read:(CBPeripheral *)peripheral;
-(void) notify:(CBPeripheral *)peripheral on:(BOOL)on;


- (void) printPeripheralInfo:(CBPeripheral*)peripheral;
-(UInt16) swap:(UInt16)s;

-(CBService *) findServiceFromUUIDEx:(CBUUID *)UUID p:(CBPeripheral *)p;
-(CBCharacteristic *) findCharacteristicFromUUIDEx:(CBUUID *)UUID service:(CBService*)service;
-(void) writeValue:(Byte *)serviceUUID characteristicUUID:(Byte *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data;
-(void) readValue: (Byte *)serviceUUID characteristicUUID:(Byte *)characteristicUUID p:(CBPeripheral *)p;
-(void) notification:(Byte *)serviceUUID characteristicUUID:(Byte *)characteristicUUID p:(CBPeripheral *)p on:(BOOL)on;
-(NSString*) bytesToHexString:(unsigned char *) bytes :(int) len;
- (void)_writeToBtDev:(NSInteger)sLen;
-(void) _readFromBtDev;
-(Byte*) hexStringToBytes:(NSString*)hexString;

-(NSInteger) recvTelcomCheck:(unsigned char *) _rData :(NSInteger) rLen;
-(void) sendCmdChinaTelecom:(int)CMD :(Byte*)data :(NSInteger)dataLen :(long)timeOut :(NSInteger) recvLen;
-(Boolean)  checkId2Data:(Byte*) data :(int) len;

struct cmdPara{
    NSInteger cmd ;
    NSInteger dataLen;
    unsigned char * sendData;
    long timeOut;
};
struct returnValue{
    NSInteger recvBuffLen;
    NSInteger returnFlag;
    unsigned char recvData[92300];
};

struct id2Txt{
 	unsigned char idname[30];
 	unsigned char idsex[2];
 	unsigned char idfolk[4];	    //36
    
 	//unsigned char idbirth[16];
 	unsigned char idyearBirth[8];
 	unsigned char idmonthBirth[4];
 	unsigned char iddayBirth[4];  //16
    
 	unsigned char idaddress[70];
 	unsigned char idnum[36];
 	unsigned char idissue[30];
 	unsigned char idstart[16];
 	unsigned char idend[16];
 	unsigned char deviceid[10];
 	unsigned char idother[26]; //100 + 104
};
struct id2Info{
    bool bHaveId2data ;//是否存在二代证数据
    struct id2Txt id2txt;
    unsigned char zpwlt[1024] ;
    bool bHaveFp;//是否存在指纹数据
    unsigned char fpdata[1024];
};
struct id2Data{
    bool bHaveId2data ;//是否存在二代证数据
    struct id2Txt id2txt;
    unsigned char zpwlt[1024] ;
    bool bHaveFp;//是否存在指纹数据
    unsigned char fpdata[1024];
};
//private function

@end
