當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript BLE.startNotification方法代碼示例

本文整理匯總了TypeScript中ionic-native.BLE.startNotification方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BLE.startNotification方法的具體用法?TypeScript BLE.startNotification怎麽用?TypeScript BLE.startNotification使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ionic-native.BLE的用法示例。


在下文中一共展示了BLE.startNotification方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: connected

    /* Record incoming data in storage */
    connected(peripheral) {

	/* Inform the peripheral of the current date */
	this.sendDate(peripheral);
	/* Subscription for the heart rate (BPM) */
	this.HRSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.heartrate);
	/* Subscription for the EKG data */
	this.EKGSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.ekg);
	/* Subscription for the bundle data */
	this.HRBundleSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.heartratebundle);
	/* Subscription for date verification */
	this.dateCheckSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck);
	/* Subscription for step count packages */
	this.stepSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.steps);
	/* Subscription for live step count */
	this.liveStepSubscription = BLE.startNotification(peripheral.id, this.scanInfo.service, this.scanInfo.livesteps);

	
	/* Subscribe to the BPM */
	this.HRSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    /* The bytes are in reverse order, so we bit shift them to form the date */
	    let date = this.calcDate(data[3],data[2],data[1],data[0]);

	    /* Record the last timestamp for data checking with peripheral */
	    this.lastDate = date;

	    console.log("Received a bpm package: " + date);

	    /* Store data (date * 1000 to account for milliseconds) */
	    this.storage.storeBPM(new Date(date * 1000),data[4]);
	    
	    /* Republish the data for the home page */
	    this.events.publish('bpm',data[4]);
	    
	    /* Post the data to the server */
	    //this.httpservice.makePostRequest(data[0],new Date(data[1] * 1000));
        });

	/* Subscribe to the EKG */
	this.EKGSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    /* Republish the data for the home page */
	    this.events.publish('ekg',data);
	});

	this.HRBundleSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);

	    /* BPMs are located every 5 indices */
	    let bpmArray = [data[4],data[9],data[14],data[19]];

	    /* Dates must be calculated in reverse order */
	    let dateArray = [
		this.calcDate(data[3],data[2],data[1],data[0]),
		this.calcDate(data[8],data[7],data[6],data[5]),
		this.calcDate(data[13],data[12],data[11],data[10]),
		this.calcDate(data[18],data[17],data[16],data[15])
	    ];

	    //console.log("Received a group data package: " + dateArray[0]);

	    /* Push all data points to storage 
	       (dates * 1000 for ms format ) */
	    for (let i=0; i < bpmArray.length; i++) {
		this.storage.storeBPM(new Date(dateArray[i] * 1000),bpmArray[i]);
	    }
	});

	/* Periodically, the peripheral may request a comparison from the last date
	   received to the current date to check if all data has arrived */
	this.dateCheckSubscription.subscribe(buffer => {
	    let data = new Uint8Array(buffer);
	    
	    let curDate = this.calcDate(data[3],data[2],data[1],data[0]);
	    if (!this.lastDate)
		return;
	    
	    let uint8 = new Uint8Array(4);

	    let caughtUp = 0;
	    if (this.lastDate >= curDate)
		caughtUp = 1;

	    /* Send back an array of the boolean result */
	    for (let i = 0; i < 4; i++) {
		uint8[i] = caughtUp;
	    }

	    BLE.write(peripheral.id, this.scanInfo.service, this.scanInfo.datecheck, uint8.buffer).then(
		succ => {console.log("wrote back: " + uint8);},
		fail => {console.log("did not write back");}
	    );
	});

	/* Step subscription contains a date, a time offset, and a number of steps */
	this.stepSubscription.subscribe(buffer => {
//.........這裏部分代碼省略.........
開發者ID:mdash-ursi2016,項目名稱:ionic_code_typescript,代碼行數:101,代碼來源:blservice.ts


注:本文中的ionic-native.BLE.startNotification方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。