版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)習(xí)報(bào)告題目心電采集專(zhuān)業(yè)學(xué)號(hào)學(xué)生指導(dǎo)教師實(shí)習(xí)時(shí)間2016年7月注:本報(bào)告僅供參考哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告一. 項(xiàng)目背景和意義實(shí)習(xí)是一種實(shí)踐,是理論聯(lián)系實(shí)際,應(yīng)用和鞏固所學(xué)專(zhuān)業(yè)知識(shí)的一項(xiàng)重要環(huán)節(jié),是培養(yǎng)我們能力和技能的一個(gè)重要手段。在今年的 7 月中旬,我們來(lái)到了東軟實(shí)訓(xùn)中心進(jìn)行為期半個(gè)月的實(shí)習(xí)。 隨著工業(yè) 4.0 的到來(lái),大數(shù)據(jù)已經(jīng)成為了各融資公司開(kāi)拓的市場(chǎng),健康也是用戶(hù)所最為關(guān)心的問(wèn)題,我們的心電采項(xiàng)目就是基于這一點(diǎn)的實(shí)習(xí)項(xiàng)目。通過(guò)采集到的受測(cè)者的心電以及數(shù)據(jù)的分析和處理,分析一個(gè)人的健康狀態(tài),不但有相當(dāng)?shù)氖袌?chǎng)前景,也為用戶(hù)了解自己的身體健康提供方便。二. 項(xiàng)目目的生產(chǎn)實(shí)習(xí)是把理論與實(shí)際相
2、結(jié)合,通過(guò)對(duì)理論知識(shí)的理解,領(lǐng)悟從而運(yùn)用到生活實(shí)際,鞏固所學(xué)有關(guān)嵌入式基礎(chǔ)理論知識(shí)和基本技能,提高對(duì)涉及知識(shí)的認(rèn)識(shí),積累經(jīng)驗(yàn)。同時(shí)生產(chǎn)實(shí)習(xí)也是大學(xué)生以學(xué)生身份到工作者身份的一種重要過(guò)渡階段。在此期間,學(xué)生能夠初次體會(huì)到實(shí)際生產(chǎn)中的種種技能與經(jīng)驗(yàn)。完成一項(xiàng)項(xiàng)目,能體現(xiàn)出獨(dú)立思考能力。Android 生產(chǎn)實(shí)習(xí)對(duì)于目前應(yīng)用現(xiàn)狀進(jìn)行了分析與比較,進(jìn)而研究分析了Android 平臺(tái)的系統(tǒng)結(jié)構(gòu)和組件模型,在基礎(chǔ)上,基于Android 平臺(tái)設(shè)計(jì)和開(kāi)發(fā),實(shí)現(xiàn)對(duì) Android 變成的理解與應(yīng)用,特別是在對(duì)于軟件的應(yīng)用生產(chǎn)很深的理解。這次實(shí)習(xí)旨在培養(yǎng)我們綜合運(yùn)用所學(xué)的軟件工程專(zhuān)業(yè)基礎(chǔ)理論、基本技能專(zhuān)業(yè)知識(shí)分析問(wèn)
3、題和解決問(wèn)題的能力,培養(yǎng)我們的專(zhuān)業(yè)素質(zhì)、應(yīng)用科學(xué)的思維方法和計(jì)算技巧,使我們了解科學(xué)研究工作的一般程序和方法,撰寫(xiě)科技論文的能力;培養(yǎng)我們直接參與科研活動(dòng)、科研文獻(xiàn)和資料的調(diào)研,對(duì)研究工作以及相關(guān)的研究結(jié)果分析、綜合的能力;重點(diǎn)培養(yǎng)我們積極的創(chuàng)新精神、嚴(yán)肅認(rèn)真的科學(xué)態(tài)度和嚴(yán)謹(jǐn)求實(shí)的工作作風(fēng),增強(qiáng)我們的綜合素質(zhì)以及對(duì)畢業(yè)后工作崗位的適應(yīng)能力;有利于擴(kuò)大我們的知識(shí)面,并掌握一些軟件工程技術(shù)的發(fā)展前沿。這是我們?cè)趯W(xué)習(xí)專(zhuān)業(yè)課程之后走向工作崗位之前的不可缺少的實(shí)踐環(huán)節(jié)。它對(duì)于培養(yǎng)我們的動(dòng)手能力有很大的意義。三. 項(xiàng)目?jī)?nèi)容我所在的班學(xué)習(xí)的是Android 手機(jī)軟件的開(kāi)發(fā)技術(shù), 以及嵌入式開(kāi)發(fā)應(yīng)用我們的任務(wù)
4、是完成一個(gè)測(cè)量心率的軟件,通過(guò)傳感器采集受測(cè)者的心跳,通過(guò) AD 采樣和定時(shí)中斷,以及藍(lán)牙,最終完成把采集到得心電數(shù)據(jù)和圖像傳送到軟件上,- 2 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告并繪制出相應(yīng)的心電圖。其中經(jīng)歷了很多困難,但是我們最后順利的完成了軟件,并通過(guò)了答辯。四. 同組分工小組共有四個(gè)成員,分為四個(gè)模塊。1.心電采集程序的編寫(xiě),以及單片機(jī)的相應(yīng)配置。2 安卓開(kāi)發(fā)的 JAVA 程序編寫(xiě)。藍(lán)牙通信的程序編寫(xiě),相應(yīng)的配置,底層文件的改寫(xiě)。PPT 的制作,以及答辯。五. 項(xiàng)目實(shí)現(xiàn)過(guò)程配置定時(shí)器,使之按照規(guī)定時(shí)間,進(jìn)入中斷程序,本項(xiàng)目利用定時(shí)器2.。#include nrf.h#include #inc
5、lude timer.hvoid timer_init(void)NRF_TIMER2 - PRESCALER = 0 x05;NRF_TIMER2 - MODE = TIMER_MODE_MODE_Timer CC2 = 0 x0A;NRF_TIMER2 - INTENSET = TIMER_INTENCLR_COMPARE2_Enabled TASKS_START = 1;void timer_stop(void)NRF_TIMER2 - TASKS_STOP = 0;以及編寫(xiě)相應(yīng)的頭文件#ifndef _TIMER_H#define _TIMER_H- 3 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告e
6、xtern void timer_init(void);extern void timer_start(void);extern void timer_stop(void);#endif利用 ADC 進(jìn)行采樣,把采集到得心電數(shù)據(jù)存儲(chǔ)到相應(yīng)的數(shù)組之中。具體包括 ADC 的配置,以及相應(yīng)的采集算法的編寫(xiě)。#include nrf.h#include #include adc.huint8_t adc_result;void adc_init(void)NRF_ADC-INTENSET=( ADC_INTENSET_END_Enabled CONFIG =(ADC_CONFIG_PSEL_Analo
7、gInput0ADC_CONFIG_PSEL_Pos) |(ADC_CONFIG_RES_8bitADC_CONFIG_RES_Pos) |(ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescalingADC_CONFIG_INPSEL_Pos) |(ADC_CONFIG_REFSEL_VBG ADC_CONFIG_REFSEL_Pos)|(ADC_CONFIG_EXTREFSEL_None EVENTS_END = 0;NRF_ADC - ENABLE =(ADC_ENABLE_ENABLE_Enabled EVENTS_END = 0;NRF_ADC -
8、TASKS_START = 1;void ADC_IRQHandle(void)if (NRF_ADC - EVENTS_END != 0)/NRF_ADC - EVENTS_END = 0;/adc_result = NRF_ADC -RESULT;- 4 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告/NRF_ADC - TASKS_STOP =1;/ 以及編寫(xiě)相應(yīng)的頭文件#ifndef ADC_H_#define ADC_H_uint8_t adc_result = 0; void adc_init(void); void adc_start(void); #endif利用 PPI,使得中斷程序的嵌套更加
9、簡(jiǎn)潔,程序更加簡(jiǎn)潔清晰。#include nrf.h#include #include ppi.hvoid ppi_init(void)NRF_PPI - CHEN = PPI_CHEN_CH0_Enabled CHG0=PPI_CHG_CH0_Included CHENSET=PPI_CHENSET_CH0_Set TASKS_CHG0.EN = 1;NRF_PPI - CH0.EEP = NRF_TIMER2-EVENTS_COMPARE2; NRF_PPI - CH0.TEP = NRF_ADC-TASKS_START;NRF_PPI - CHENSET = 1; /NRF_PPI -
10、CHG0 = 1;以及相應(yīng)的頭文件的編寫(xiě)。#ifndef PPI_H_#define PPI_H_uint8_t adc_result = 0; extern void ppi_init(void); #endif為了把采集到的心電數(shù)據(jù)進(jìn)行發(fā)送,要利用藍(lán)牙,并且通過(guò)相應(yīng)的配置使得相應(yīng)的數(shù)據(jù)可以利用軟件畫(huà)出圖像。相應(yīng)的藍(lán)牙程序如下。/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.*The information contained herein is property of Nordic Semiconductor
11、ASA.Terms and conditions of usage are described in detail in NORDICSEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.*- 5 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告Licensees are granted free, non-transferable use of the information. NOWARRANTY of ANY KIND is provided. This heading must NOT be removedfrom* the file./* Attention
12、!*To maintain compliance with Nordic Semiconductor ASA s Bluetooth profilequalification listings, this section of source code must not be modified. #include ble_hrs.h#include #include nordic_common.h#include ble_l2cap.h#include ble_srv_common.h#include app_util.h#defineOPCODE_LENGTH1/* Length of opc
13、ode inside Heart Rate Measurement packet. */#defineHANDLE_LENGTH2/* Length of handle inside Heart Rate Measurement packet. */#define MAX_HRM_LEN(BLE_L2CAP_MTU_DEF - OPCODE_LENGTH -HANDLE_LENGTH)/* Maximum size of a transmitted Heart Rate Measurement.#define INITIAL_V ALUE_HRM0/* Initial Heart Rate M
14、easurement value. */ Heart Rate Measurement flag bits#define HRM_FLAG_MASK_HR_V ALUE_16BIT(0 x01 0)/* Heart Rate Value Format bit. */#define HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED(0 x01 1)/* Sensor Contact Detected bit. */#define HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED(0 x01 2)/* Sensor Contact Suppor
15、ted bit. */#define HRM_FLAG_MASK_EXPENDED_ENERGY_INCLUDED (0 x01 3)/* Energy Expended Status bit. Feature Not Supported */#define HRM_FLAG_MASK_RR_INTERV AL_INCLUDED(0 x01 4)/*conn_handle = p_ble_evt-evt.gap_evt.conn_handle;/*brief Function for handling the Disconnect event.* paraminp_hrsHeart Rate
16、Service structure.* paraminp_ble_evtEvent received from the BLE stack.static void on_disconnect(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)UNUSED_PARAMETER(p_ble_evt);- 6 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告p_hrs-conn_handle = BLE_CONN_HANDLE_INV ALID;/*briefFunction for handling write events to the Heart Rate Measurementc
17、haracteristic.* paraminp_hrsHeart Rate Service structure.* paraminp_evt_writeWrite event received from the BLE stack.*/static void on_hrm_cccd_write(ble_hrs_t * p_hrs, ble_gatts_evt_write_t * p_evt_write)if (p_evt_write-len = 2)CCCD written, update notification state if (p_hrs-evt_handler != NULL)bl
18、e_hrs_evt_t evt;if (ble_srv_is_notification_enabled(p_evt_write-data)evt.evt_type=BLE_HRS_EVT_NOTIFICATION_ENABLED;elseevt.evt_type=BLE_HRS_EVT_NOTIFICATION_DISABLED;p_hrs-evt_handler(p_hrs, &evt);/*brief Function for handling the Write event.* paraminp_hrsHeart Rate Service structure.* paraminp_ble
19、_evtEvent received from the BLE stack.*/static void on_write(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)ble_gatts_evt_write_t * p_evt_write = &p_ble_evt-evt.gatts_evt.params.write;if (p_evt_write-handle = p_hrs-hrm_handles.cccd_handle)on_hrm_cccd_write(p_hrs, p_evt_write);- 7 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告void ble_hr
20、s_on_ble_evt(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)switch (p_ble_evt-header.evt_id)case BLE_GAP_EVT_CONNECTED:on_connect(p_hrs, p_ble_evt);break;case BLE_GAP_EVT_DISCONNECTED:on_disconnect(p_hrs, p_ble_evt);break;case BLE_GATTS_EVT_WRITE:on_write(p_hrs, p_ble_evt);break;default:No implementation
21、needed. break;/*brief Function for encoding a Heart Rate Measurement.* paraminp_hrsHeart Rate Service structure.* paraminheart_rateMeasurement to be encoded.* paramoutp_encoded_bufferBuffer where the encoded data willbewritten.* returnSize of encoded data.*/static uint8_thrm_encode(ble_hrs_t *p_hrs,
22、 uint16_t heart_rate, uint8_t*p_encoded_buffer)uint8_t flags = 0;uint8_t len= 1;inti;/ Set sensor contact related flagsif (p_hrs-is_sensor_contact_supported)flags |= HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED;if (p_hrs-is_sensor_contact_detected)flags |= HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED;- 8 -哈爾濱工業(yè)大
23、學(xué)本科實(shí)習(xí)報(bào)告Encode heart rate measurement if (heart_rate 0 xff)flags |= HRM_FLAG_MASK_HR_V ALUE_16BIT;len+= uint16_encode(heart_rate, &p_encoded_bufferlen);elsep_encoded_bufferlen+ = (uint8_t)heart_rate;/ Encode rr_interval valuesif (p_hrs-rr_interval_count 0)flags |= HRM_FLAG_MASK_RR_INTERV AL_INCLUDED;
24、for (i = 0; i rr_interval_count; i+)if (len + sizeof(uint16_t) MAX_HRM_LEN)Not all stored rr_interval values can fit into the encoded hrm,move the remaining values to the start of the buffer. memmove(&p_hrs-rr_interval0,&p_hrs-rr_intervali,(p_hrs-rr_interval_count - i) * sizeof(uint16_t);break;len +
25、= uint16_encode(p_hrs-rr_intervali, &p_encoded_bufferlen);p_hrs-rr_interval_count -= i;/ Add flagsp_encoded_buffer0 = flags;return len;/*brief Function for adding the Heart Rate Measurement characteristic.* paraminp_hrsHeart Rate Service structure.* paraminp_hrs_initInformation needed to initialize
26、the service.* returnNRF_SUCCESS on success, otherwise an error code.*/static uint32_t heart_rate_measurement_char_add(ble_hrs_t* p_hrs,- 9 -哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告const ble_hrs_init_t *p_hrs_init)ble_gatts_char_md_t char_md;ble_gatts_attr_md_t cccd_md;ble_gatts_attr_tattr_char_value;ble_uuid_tble_uuid;ble_gat
27、ts_attr_md_t attr_md;uint8_t encoded_initial_hrmMAX_HRM_LEN; memset(&cccd_md, 0, sizeof(cccd_md);BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm); cccd_md.write_perm = p_hrs_init-hrs_hrm_attr_md.cccd_write_perm;cccd_md.vloc= BLE_GATTS_VLOC_STACK;memset(&char_md, 0, sizeof(char_md);char_md.char_pro
28、ps.notify = 1;char_md.p_char_user_desc = NULL;char_md.p_char_pf= NULL;char_md.p_user_desc_md= NULL;char_md.p_cccd_md= &cccd_md;char_md.p_sccd_md= NULL;BLE_UUID_BLE_ASSIGN(ble_uuid,BLE_UUID_HEART_RATE_MEASUREMENT_CHAR);memset(&attr_md, 0, sizeof(attr_md);attr_md.read_perm = p_hrs_init-hrs_hrm_attr_md
29、.read_perm; attr_md.write_perm = p_hrs_init-hrs_hrm_attr_md.write_perm;attr_md.vloc= BLE_GATTS_VLOC_STACK;attr_md.rd_auth= 0;attr_md.wr_auth= 0;attr_md.vlen= 1;memset(&attr_char_value, 0, sizeof(attr_char_value);attr_char_value.p_uuid= &ble_uuid;attr_char_value.p_attr_md = &attr_md;attr_char_value.i
30、nit_len=hrm_encode(p_hrs, INITIAL_V ALUE_HRM,encoded_initial_hrm);attr_char_value.init_offs = 0;attr_char_value.max_len= MAX_HRM_LEN;attr_char_value.p_value= encoded_initial_hrm;-10-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告return sd_ble_gatts_characteristic_add(p_hrs-service_handle,&char_md,&attr_char_value,&p_hrs-hrm_handles)
31、;/*brief Function for adding the Body Sensor Location characteristic.* paraminp_hrsHeart Rate Service structure.* paraminp_hrs_initInformation needed to initialize the service.* returnNRF_SUCCESS on success, otherwise an error code.*/staticuint32_tbody_sensor_location_char_add(ble_hrs_t *p_hrs,const
32、ble_hrs_init_t * p_hrs_init)ble_gatts_char_md_t char_md;ble_gatts_attr_tattr_char_value;ble_uuid_tble_uuid;ble_gatts_attr_md_t attr_md;memset(&char_md, 0, sizeof(char_md);char_md.char_props.read = 1;char_md.p_char_user_desc = NULL;char_md.p_char_pf= NULL;char_md.p_user_desc_md= NULL;char_md.p_cccd_m
33、d= NULL;char_md.p_sccd_md= NULL;BLE_UUID_BLE_ASSIGN(ble_uuid,BLE_UUID_BODY_SENSOR_LOCATION_CHAR);memset(&attr_md, 0, sizeof(attr_md);attr_md.read_perm = p_hrs_init-hrs_bsl_attr_md.read_perm; attr_md.write_perm = p_hrs_init-hrs_bsl_attr_md.write_perm;attr_md.vloc= BLE_GATTS_VLOC_STACK;attr_md.rd_auth
34、= 0;attr_md.wr_auth= 0;attr_md.vlen= 0;memset(&attr_char_value, 0, sizeof(attr_char_value);attr_char_value.p_uuid= &ble_uuid;-11-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告attr_char_value.p_attr_md = &attr_md;attr_char_value.init_len= sizeof (uint8_t);attr_char_value.init_offs = 0;attr_char_value.max_len= sizeof (uint8_t);attr_c
35、har_value.p_value= p_hrs_init-p_body_sensor_location;return sd_ble_gatts_characteristic_add(p_hrs-service_handle,&char_md,&attr_char_value,&p_hrs-bsl_handles);uint32_t ble_hrs_init(ble_hrs_t * p_hrs, const ble_hrs_init_t * p_hrs_init)uint32_terr_code;ble_uuid_t ble_uuid;/ Initialize service structur
36、ep_hrs-evt_handler= p_hrs_init-evt_handler;p_hrs-is_sensor_contact_supported=p_hrs_init-is_sensor_contact_supported;p_hrs-conn_handle=BLE_CONN_HANDLE_INV ALID;p_hrs-is_sensor_contact_detected = false;p_hrs-rr_interval_count= 0;/ Add serviceBLE_UUID_BLE_ASSIGN(ble_uuid,BLE_UUID_HEART_RATE_SERVICE);er
37、r_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,&ble_uuid,&p_hrs-service_handle);if (err_code != NRF_SUCCESS)return err_code;/ Add heart rate measurement characteristicerr_code = heart_rate_measurement_char_add(p_hrs, p_hrs_init);if (err_code != NRF_SUCCESS)return err_code;-12-哈爾濱工業(yè)大學(xué)本
38、科實(shí)習(xí)報(bào)告if (p_hrs_init-p_body_sensor_location != NULL)/ Add body sensor location characteristicerr_code = body_sensor_location_char_add(p_hrs, p_hrs_init); if (err_code != NRF_SUCCESS) return err_code;return NRF_SUCCESS;uint32_t ble_hrs_heart_rate_measurement_send(ble_hrs_t* p_hrs, uint16_t heart_rate)
39、uint32_t err_code;/ Send value if connected and notifyingif (p_hrs-conn_handle != BLE_CONN_HANDLE_INV ALID)uint8_tencoded_hrmMAX_HRM_LEN;uint16_tlen;uint16_thvx_len;ble_gatts_hvx_params_t hvx_params;len = hrm_encode(p_hrs, heart_rate, encoded_hrm); hvx_len = len;memset(&hvx_params, 0, sizeof(hvx_par
40、ams);hvx_params.handle = p_hrs-hrm_handles.value_handle; hvx_params.type = BLE_GATT_HVX_NOTIFICATION; hvx_params.offset = 0;hvx_params.p_len= &hvx_len;hvx_params.p_data = encoded_hrm;err_code = sd_ble_gatts_hvx(p_hrs-conn_handle, &hvx_params); if (err_code = NRF_SUCCESS) & (hvx_len != len)err_code =
41、 NRF_ERROR_DATA_SIZE;-13-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告elseerr_code = NRF_ERROR_INVALID_STATE;return err_code;void ble_hrs_rr_interval_add(ble_hrs_t * p_hrs, uint16_t rr_interval)if(p_hrs-rr_interval_count=BLE_HRS_MAX_BUFFERED_RR_INTERV ALS)The rr_interval buffer is full, delete the oldest value memmove(&p_hrs-rr_in
42、terval0,&p_hrs-rr_interval1,(BLE_HRS_MAX_BUFFERED_RR_INTERV ALS - 1) *sizeof(uint16_t);p_hrs-rr_interval_count-;/ Add new valuep_hrs-rr_intervalp_hrs-rr_interval_count+ = rr_interval;bool ble_hrs_rr_interval_buffer_is_full(ble_hrs_t * p_hrs)return (p_hrs-rr_interval_count = BLE_HRS_MAX_BUFFERED_RR_I
43、NTERV ALS);uint32_t ble_hrs_sensor_contact_supported_set(ble_hrs_t * p_hrs, bool is_sensor_contact_supported)/ Check if we are connected to peerif (p_hrs-conn_handle = BLE_CONN_HANDLE_INV ALID)p_hrs-is_sensor_contact_supported = is_sensor_contact_supported; return NRF_SUCCESS;elsereturn NRF_ERROR_IN
44、VALID_STATE;-14-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告void ble_hrs_sensor_contact_detected_update(ble_hrs_t * p_hrs, bool is_sensor_contact_detected)p_hrs-is_sensor_contact_detected = is_sensor_contact_detected;uint32_t ble_hrs_body_sensor_location_set(ble_hrs_t * p_hrs, uint8_t body_sensor_location)uint16_t len = sizeof(ui
45、nt8_t);return sd_ble_gatts_value_set(p_hrs-bsl_handles.value_handle,0, &len, &body_sensor_location);實(shí)現(xiàn)項(xiàng)目功能的主函數(shù)/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.*The information contained herein is property of Nordic Semiconductor ASA.Terms and conditions of usage are described in detai
46、l in NORDICSEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.*Licensees are granted free, non-transferable use of the information. NOWARRANTY of ANY KIND is provided. This heading must NOT be removedfrom* the file.*/* Attention!To maintain compliance with Nordic Semiconductor ASA s Bluetooth profile
47、qualification listings, this section of source code must not be modified.*/#include ble_hrs.h#include #include nordic_common.h#include ble_l2cap.h#include ble_srv_common.h#include app_util.h-15-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告#defineOPCODE_LENGTH1/* Length of opcode inside Heart Rate Measurement packet. */#defineHANDL
48、E_LENGTH2/* Length of handle inside Heart Rate Measurement packet. */#define MAX_HRM_LEN(BLE_L2CAP_MTU_DEF - OPCODE_LENGTH -HANDLE_LENGTH) /* Maximum size of a transmitted Heart Rate Measurement. */#define INITIAL_V ALUE_HRM0/* Initial Heart Rate Measurement value. */ Heart Rate Measurement flag bit
49、s#define HRM_FLAG_MASK_HR_V ALUE_16BIT(0 x01 0)/* Heart Rate Value Format bit. */#define HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED(0 x01 1)/* Sensor Contact Detected bit. */#define HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED(0 x01 2)/* Sensor Contact Supported bit. */#define HRM_FLAG_MASK_EXPENDED_ENERGY_INC
50、LUDED (0 x01 3)/* Energy Expended Status bit. Feature Not Supported */#define HRM_FLAG_MASK_RR_INTERV AL_INCLUDED(0 x01 4)/*conn_handle = p_ble_evt-evt.gap_evt.conn_handle;/*brief Function for handling the Disconnect event.* paraminp_hrsHeart Rate Service structure.* paraminp_ble_evtEvent received f
51、rom the BLE stack.*/static void on_disconnect(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)UNUSED_PARAMETER(p_ble_evt);p_hrs-conn_handle = BLE_CONN_HANDLE_INV ALID;-16-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告/*brief Function for handling write events to the Heart Rate Measurement characteristic.* paraminp_hrsHeart Rate Service st
52、ructure.* paraminp_evt_writeWrite event received from the BLE stack.*/static void on_hrm_cccd_write(ble_hrs_t * p_hrs, ble_gatts_evt_write_t * p_evt_write)if (p_evt_write-len = 2)CCCD written, update notification state if (p_hrs-evt_handler != NULL)ble_hrs_evt_t evt;if (ble_srv_is_notification_enabl
53、ed(p_evt_write-data)evt.evt_type=BLE_HRS_EVT_NOTIFICATION_ENABLED;elseevt.evt_type=BLE_HRS_EVT_NOTIFICATION_DISABLED;p_hrs-evt_handler(p_hrs, &evt);/*brief Function for handling the Write event.* paraminp_hrsHeart Rate Service structure.* paraminp_ble_evtEvent received from the BLE stack.*/static vo
54、id on_write(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)ble_gatts_evt_write_t*p_evt_write=&p_ble_evt-evt.gatts_evt.params.write;if (p_evt_write-handle = p_hrs-hrm_handles.cccd_handle)-17-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告on_hrm_cccd_write(p_hrs, p_evt_write);void ble_hrs_on_ble_evt(ble_hrs_t * p_hrs, ble_evt_t * p_ble_evt)
55、switch (p_ble_evt-header.evt_id)case BLE_GAP_EVT_CONNECTED:on_connect(p_hrs, p_ble_evt);break;case BLE_GAP_EVT_DISCONNECTED:on_disconnect(p_hrs, p_ble_evt);break;case BLE_GATTS_EVT_WRITE:on_write(p_hrs, p_ble_evt);break;default:No implementation needed. break;/*brief Function for encoding a Heart Ra
56、te Measurement.* paraminp_hrsHeart Rate Service structure.* paraminheart_rateMeasurement to be encoded.* paramoutp_encoded_bufferBuffer where the encoded data willbewritten.* returnSize of encoded data.*/static uint8_thrm_encode(ble_hrs_t *p_hrs, uint16_t heart_rate, uint8_t*p_encoded_buffer)uint8_t
57、 flags = 0;uint8_t len= 1;inti;/ Set sensor contact related flags-18-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告if (p_hrs-is_sensor_contact_supported)flags |= HRM_FLAG_MASK_SENSOR_CONTACT_SUPPORTED;if (p_hrs-is_sensor_contact_detected)flags |= HRM_FLAG_MASK_SENSOR_CONTACT_DETECTED;Encode heart rate measurement if (heart_rate 0 x
58、ff)flags |= HRM_FLAG_MASK_HR_V ALUE_16BIT;len+= uint16_encode(heart_rate, &p_encoded_bufferlen);elsep_encoded_bufferlen+ = (uint8_t)heart_rate;/ Encode rr_interval valuesif (p_hrs-rr_interval_count 0)flags |= HRM_FLAG_MASK_RR_INTERV AL_INCLUDED;for (i = 0; i rr_interval_count; i+)if (len + sizeof(ui
59、nt16_t) MAX_HRM_LEN)Not all stored rr_interval values can fit into the encoded hrm,move the remaining values to the start of the buffer. memmove(&p_hrs-rr_interval0,&p_hrs-rr_intervali,(p_hrs-rr_interval_count - i) * sizeof(uint16_t);break;len += uint16_encode(p_hrs-rr_intervali, &p_encoded_bufferle
60、n);p_hrs-rr_interval_count -= i;/ Add flagsp_encoded_buffer0 = flags;return len;-19-哈爾濱工業(yè)大學(xué)本科實(shí)習(xí)報(bào)告/*brief Function for adding the Heart Rate Measurement characteristic.* paraminp_hrsHeart Rate Service structure.* paraminp_hrs_initInformation needed to initialize the service.* returnNRF_SUCCESS on suc
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 向他人付傭金合同范例
- 工程抵押房買(mǎi)賣(mài)合同范例
- 公司租用汽車(chē)合同范例
- 勞務(wù)清包工合同范例
- 廠長(zhǎng)期維護(hù)合同范例
- 農(nóng)業(yè)訂貨合同范例
- 房屋借用名字合同范例
- 養(yǎng)豬租房合同范例
- 家用商品銷(xiāo)售合同范例
- 水泥混凝土購(gòu)銷(xiāo)合同范例
- 氣相色譜檢測(cè)器FID-培訓(xùn)講解課件
- 新教材人教A版高中數(shù)學(xué)選擇性必修第一冊(cè)全冊(cè)教學(xué)課件
- 《HSK標(biāo)準(zhǔn)教程1》-HSK1-L8課件
- 幼兒園小班繪本:《藏在哪里了》 課件
- 上冊(cè)外研社六年級(jí)英語(yǔ)復(fù)習(xí)教案
- 替班換班登記表
- 社會(huì)保險(xiǎn)法 課件
- 阿利的紅斗篷 完整版課件PPT
- 橋梁工程擋土墻施工
- 供應(yīng)商質(zhì)量問(wèn)題處理流程范文
- 實(shí)驗(yàn)室生物安全手冊(cè)(完整版)資料
評(píng)論
0/150
提交評(píng)論